From nobody Thu Oct 24 19:26:05 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XZG9T56cqz5Zmrc; Thu, 24 Oct 2024 19:26:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XZG9T4ZxSz4pmJ; Thu, 24 Oct 2024 19:26:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729797965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lB2sDF+KoXHpdoQI0+Wptr838/DR6nSDgfv8BPTFO10=; b=aU0Gtq+0wkKlrjOIKjFG2LgN+xXUmQOsuQYfzPiTwzw/0qW23autewhG9rMF/4x7PXOJMe eYKl9YrN+vrmA2JHCUhzYTcWd2+Cx4Rp93tkYzMT2JH8ljYXpCShEkf5nheoEIlcDs8o+m cUlJkoE1YzgXEcqxb0OPgLd6d8NfNm8Zn8dg98L6PYFTcJ56X5HIEzdTS33yQ7mi2x2/e7 t7GYsd7rUcHQg9PBsDc9NlyZHC5wm9geswBgEER8ZzRjHpZ6W/oOgKgOuegPRAOTrUkWC8 vLfZvA2SvCOKqvWcWcEjEHaFg32HIlIt9kKlH1F2HGoralgNDWHe3V+wNUm8ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729797965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lB2sDF+KoXHpdoQI0+Wptr838/DR6nSDgfv8BPTFO10=; b=QxTs37Xc4C7yygs8nI0s+KW5aOVpqt+8e4CS13PG+PZI4RomOqZXFT9ZXFXvfRxw1L7UEI EBi/l3BgFfflAvdCkBtuH2bd4lHCd69xKFtPocXQw+xE9BkM1It+Q68TVkv5ACPNPAXY7A krFYNo3pJuYq39bEc5G/dyHBaoMbakj63kY3CmHmdlIjj+qr+LsdJ60TSUb0GqWrfwSCaW 07FEQX7SnhyZl3FOxoTjidTck1KYJmz35GRMVJKAMbCETGPKIhl81oHAhXtLqoPUsNMOuw y+pvu0ipVvt9MsBM+NcTDKCtv4BW4/cVhvcd4lnbRE2o/cqLu5HZQ/3EdX9eoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729797965; a=rsa-sha256; cv=none; b=s75LCLayxeeh/6eBELz6mIdPudz1LvWTd8NzzA9XUZTW7zhmI90HkiAtBlakiEj25JDWFO VQMrzUAI9TJFccwVLWt4RQz1ZrhiNDK2qdabmPPagmrxm4L8gP7EOMrNywTB37Mb9eiFCw e5uWo1MYtTl7hTyGCrJMWdtZQivYeFTdu8nGWp46BzboFN3JhOHvpu+fc1vaEy8SK2qybj McfRdKO0aznZxucqyTuyVQkF+EygeQRJQ7MSb45TdZYFpY9AdbJQBQfoPeSFWCCj166CR7 KIzoT005i8MSWdo/ekH/yJeZQIPYpurS0O4by0cV7nUBMWM6Cx25pKQ91aDGRQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XZG9T4B5GzvxD; Thu, 24 Oct 2024 19:26:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49OJQ5uq040575; Thu, 24 Oct 2024 19:26:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49OJQ5SW040572; Thu, 24 Oct 2024 19:26:05 GMT (envelope-from git) Date: Thu, 24 Oct 2024 19:26:05 GMT Message-Id: <202410241926.49OJQ5SW040572@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: db08b0b04dec - main - tmpfs_vnops: move swap work to swap_pager List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: db08b0b04deced766c3b5f07bcfb82333666226c Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=db08b0b04deced766c3b5f07bcfb82333666226c commit db08b0b04deced766c3b5f07bcfb82333666226c Author: Doug Moore AuthorDate: 2024-10-24 19:24:49 +0000 Commit: Doug Moore CommitDate: 2024-10-24 19:24:49 +0000 tmpfs_vnops: move swap work to swap_pager Two functions in tmpfs_vnops.c use an interface provided by swap_pager.c. Move most of the implementation of those functions to swap_pager.c so that they can be implemented more effectively, with access to implementation details of the swap pager. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D47212 --- sys/fs/tmpfs/tmpfs_vnops.c | 60 ++++------------------------------------------ sys/vm/swap_pager.c | 58 +++++++++++++++++++++++++++++++++++++++----- sys/vm/swap_pager.h | 3 ++- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index c2559a61fe37..428c31f3c59a 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -2092,40 +2092,10 @@ tmpfs_setextattr(struct vop_setextattr_args *ap) static off_t tmpfs_seek_data_locked(vm_object_t obj, off_t noff) { - vm_page_t m; - vm_pindex_t p, p_swp; + vm_pindex_t p; - p = OFF_TO_IDX(noff); - m = vm_page_find_least(obj, p); - - /* - * Microoptimize the most common case for SEEK_DATA, where - * there is no hole and the page is resident. - */ - if (m != NULL && m->pindex == p && vm_page_any_valid(m)) - return (noff); - - p_swp = swap_pager_find_least(obj, p); - if (p_swp == p) - return (noff); - - /* - * Find the first resident page after p, before p_swp. - */ - while (m != NULL && m->pindex < p_swp) { - if (vm_page_any_valid(m)) - return (IDX_TO_OFF(m->pindex)); - m = TAILQ_NEXT(m, listq); - } - if (p_swp == OBJ_MAX_SIZE) - p_swp = obj->size; - return (IDX_TO_OFF(p_swp)); -} - -static off_t -tmpfs_seek_next(off_t noff) -{ - return (noff + PAGE_SIZE - (noff & PAGE_MASK)); + p = swap_pager_seek_data(obj, OFF_TO_IDX(noff)); + return (p == OFF_TO_IDX(noff) ? noff : IDX_TO_OFF(p)); } static int @@ -2142,30 +2112,8 @@ tmpfs_seek_clamp(struct tmpfs_node *tn, off_t *noff, bool seekdata) static off_t tmpfs_seek_hole_locked(vm_object_t obj, off_t noff) { - vm_page_t m; - vm_pindex_t p, p_swp; - - for (;; noff = tmpfs_seek_next(noff)) { - /* - * Walk over the largest sequential run of the valid pages. - */ - for (m = vm_page_lookup(obj, OFF_TO_IDX(noff)); - m != NULL && vm_page_any_valid(m); - m = vm_page_next(m), noff = tmpfs_seek_next(noff)) - ; - /* - * Found a hole in the object's page queue. Check if - * there is a hole in the swap at the same place. - */ - p = OFF_TO_IDX(noff); - p_swp = swap_pager_find_least(obj, p); - if (p_swp != p) { - noff = IDX_TO_OFF(p); - break; - } - } - return (noff); + return (IDX_TO_OFF(swap_pager_seek_hole(obj, OFF_TO_IDX(noff)))); } static int diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 5eccc621bdae..90d44d3e7402 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -111,6 +111,7 @@ #include #include #include +#include #include #include #include @@ -2476,17 +2477,62 @@ swap_pager_iter_find_least(struct pctrie_iter *blks, vm_pindex_t pindex) } /* - * Returns the least page index which is greater than or equal to the parameter - * pindex and for which there is a swap block allocated. Returns OBJ_MAX_SIZE - * if are no allocated swap blocks for the object after the requested pindex. + * Find the first index >= pindex that has either a valid page or a swap + * block. */ vm_pindex_t -swap_pager_find_least(vm_object_t object, vm_pindex_t pindex) +swap_pager_seek_data(vm_object_t object, vm_pindex_t pindex) { - struct pctrie_iter blks; + struct pctrie_iter blks, pages; + vm_page_t m; + vm_pindex_t swap_index; + + VM_OBJECT_ASSERT_WLOCKED(object); + vm_page_iter_init(&pages, object); + m = vm_page_iter_lookup_ge(&pages, pindex); + if (m != NULL) { + if (!vm_page_any_valid(m)) + m = NULL; + else if (pages.index == pindex) + return (pages.index); + } + swblk_iter_init_only(&blks, object); + swap_index = swap_pager_iter_find_least(&blks, pindex); + if (swap_index == pindex) + return (swap_index); + if (swap_index == OBJ_MAX_SIZE) + swap_index = object->size; + if (m == NULL) + return (swap_index); + + while ((m = vm_radix_iter_step(&pages)) != NULL && + pages.index < swap_index) { + if (vm_page_any_valid(m)) + return (pages.index); + } + return (swap_index); +} + +/* + * Find the first index >= pindex that has neither a valid page nor a swap + * block. + */ +vm_pindex_t +swap_pager_seek_hole(vm_object_t object, vm_pindex_t pindex) +{ + struct pctrie_iter blks, pages; + struct swblk *sb; + vm_page_t m; + VM_OBJECT_ASSERT_WLOCKED(object); + vm_page_iter_init(&pages, object); swblk_iter_init_only(&blks, object); - return (swap_pager_iter_find_least(&blks, pindex)); + while (((m = vm_page_iter_lookup(&pages, pindex)) != NULL && + vm_page_any_valid(m)) || + ((sb = swblk_iter_lookup(&blks, pindex)) != NULL && + sb->d[pindex % SWAP_META_PAGES] != SWAPBLK_NONE)) + pindex++; + return (pindex); } /* diff --git a/sys/vm/swap_pager.h b/sys/vm/swap_pager.h index ade94802b963..3287886026f7 100644 --- a/sys/vm/swap_pager.h +++ b/sys/vm/swap_pager.h @@ -74,8 +74,9 @@ extern int nsw_cluster_max; struct xswdev; int swap_dev_info(int name, struct xswdev *xs, char *devname, size_t len); void swap_pager_copy(vm_object_t, vm_object_t, vm_pindex_t, int); -vm_pindex_t swap_pager_find_least(vm_object_t object, vm_pindex_t pindex); bool swap_pager_scan_all_shadowed(vm_object_t object); +vm_pindex_t swap_pager_seek_data(vm_object_t object, vm_pindex_t pindex); +vm_pindex_t swap_pager_seek_hole(vm_object_t object, vm_pindex_t pindex); void swap_pager_freespace(vm_object_t object, vm_pindex_t start, vm_size_t size, vm_size_t *freed); void swap_pager_swap_init(void);