From patchwork Fri Jun 9 01:35:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13273085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 777C8C7EE29 for ; Fri, 9 Jun 2023 01:35:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1780F8E0002; Thu, 8 Jun 2023 21:35:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1282E8E0001; Thu, 8 Jun 2023 21:35:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 017928E0002; Thu, 8 Jun 2023 21:35:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E840E8E0001 for ; Thu, 8 Jun 2023 21:35:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B9DF21A0369 for ; Fri, 9 Jun 2023 01:35:21 +0000 (UTC) X-FDA: 80881491642.15.DC982BC Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf10.hostedemail.com (Postfix) with ESMTP id EC323C0002 for ; Fri, 9 Jun 2023 01:35:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Sak7mjF3; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686274520; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hzsL+M6cdepZgQw4hIUfWIci6E11MaKNkaWhV1yArkY=; b=y7cOZfrmEC9DGwg6pOMEo3UG8woSL680vWv27qldTMi1x0skHaKS1wMmoHlrzcI47Gx847 ckmnCjOnHrpazhI5fAaWKmsO/7r0nZRdcUMmdqNlJmGkHKWAxjHleLqs2awmV4No43ieex 7pCmoPqfkM3aD7RXq2kcHwlKYTprfew= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686274520; a=rsa-sha256; cv=none; b=EZsNv2JdRHteui/K5nwak7cjG+aetay/pAtc4ppfiLOGsyISW5K9aKfnP06xc5FnqFv2Ci epoYJR1wSQ0K2m2Q9UZ2XAn9wgoaObW7cXjoKW1vDUcjj9f2oIiT/95XB1pXbNiSAiB4da cA1ua41+YMFH9jZlTUIatLsqfv/R5kw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Sak7mjF3; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-565cdb77b01so10931267b3.0 for ; Thu, 08 Jun 2023 18:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686274519; x=1688866519; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=hzsL+M6cdepZgQw4hIUfWIci6E11MaKNkaWhV1yArkY=; b=Sak7mjF34nMHTvCHP5NeKRtkES8TSscUHlyC9R0R46SCrhEJJ2Wo+n7dfWrX77uQe8 nf+QSJZI16aTp4GUl6IGu9WutySoxO4BhydtYaduPdP51lxLi8Eo7UzEJvf+9zsLlQKg 1uAWQEdqAQK63Qji2NQKBkmHFaElkPHhKBew+iyAcD1FGdj+qH73dMkXTiCWxIZUVbNy fXN+aUpQp9yRvXbnP1DZhFGyMAkNlSUaOV8BRQ3aucz5IbMfcsCH3z+WaSedYI9tzU4M sRC3DhkA8g6Vrf7EurgcGfyAeEcYsIRAt7OjP2hbNUKH6TRoKes6M9tBjy+ai0vdg3/i pdHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686274519; x=1688866519; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hzsL+M6cdepZgQw4hIUfWIci6E11MaKNkaWhV1yArkY=; b=ggsO9jMdKWyKVSPr3RFLjlemLBebfKsnUlg0lxenOHKcv3IvFQB9kkkEyVhALZT6Fr /efWhJDUHaXFHZeBxQrvJTKKs737Fg8DXpma6uVmMGe/UQVWxqNY7vg4CjWI/T+IAByA pRQ0sEYQ96qmuUCa1bLhr22oYv7mehSRuhm87TCYS5Xq3feJtXipUj+D60mvkyB4NdzV 9beVYBqBA7kZCkBHGpcehfx1RTZp+xonNzh2NWotDKu1tiU0b9i8qoIBiSqMHF6r2PTZ 4s5DyW7q9UgtYVdgb1tHbvyNYaDXkJRG/F84UVY8EvnVlkleaOH2W/ugMJMeBHrPXBiL QL5w== X-Gm-Message-State: AC+VfDxu4WyOqBOarzRdDHzw+ikMIlrkon7yos4hb+SM8sTlpKg4tF5Q mYBq26BTyuGvO5lAb/QsKVmT0A== X-Google-Smtp-Source: ACHHUZ4AK/lYHw0bDyLVKmEksYxVFlrDP4tGf35FRUzn6cSvs6hJCxMo87mkPkKs2nriI5iLhLUP+g== X-Received: by 2002:a81:4e04:0:b0:568:ea0e:ae75 with SMTP id c4-20020a814e04000000b00568ea0eae75mr1286809ywb.45.1686274518944; Thu, 08 Jun 2023 18:35:18 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id s4-20020a81bf44000000b0054601ee157fsm283836ywk.114.2023.06.08.18.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:35:18 -0700 (PDT) Date: Thu, 8 Jun 2023 18:35:14 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 21/32] mm/madvise: clean up force_shm_swapin_readahead() In-Reply-To: Message-ID: <67e18875-ffb3-ec27-346-f350e07bed87@google.com> References: MIME-Version: 1.0 X-Stat-Signature: fipcg36wjdc5g9r31sgx397n1bmeedtd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EC323C0002 X-Rspam-User: X-HE-Tag: 1686274519-740381 X-HE-Meta: U2FsdGVkX1/lex79Zmlco44sbX/Vb8a9eTWBSCN3XKJ7l+ML3gVASyS/ITY48+tPGm8zzxPZr7HiQBp9oXzkCm/yKWPA1Bd8EmAT5hLWuC4N5LkxbaCzrNtThqssJNRhbM6H1Ip9k3EUAHpjVjk9LtHvO4Y77upK4Wl8yOpMdF3re+W8r1c09tVPSlkRnVHhB8x9Y4F9rLm8I40cB1uMgdZYN5kFXWClFuAdsqzFbAchKmSKAl/CDPdD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7q1tBHq+U0MzoxZncuhoCft35OOQeKE5Fp3kQy8KZSTQDAs8bnjdHEUOKzsayCgK5AviS0m44rDYJ/Cjk0QSRDpnEAD7fZl+HaSCNN11g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Some nearby MADV_WILLNEED cleanup unrelated to pte_offset_map_lock(). shmem_swapin_range() is a better name than force_shm_swapin_readahead(). Fix unimportant off-by-one on end_index. Call the swp_entry_t "entry" rather than "swap": either is okay, but entry is the name used elsewhere in mm/madvise.c. Do not assume GFP_HIGHUSER_MOVABLE: that's right for anon swap, but shmem should take gfp from mapping. Pass the actual vma and address to read_swap_cache_async(), in case a NUMA mempolicy applies. lru_add_drain() at outer level, like madvise_willneed()'s other branch. Signed-off-by: Hugh Dickins --- mm/madvise.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 0af64c4a8f82..9b3c9610052f 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -235,30 +235,34 @@ static const struct mm_walk_ops swapin_walk_ops = { .pmd_entry = swapin_walk_pmd_entry, }; -static void force_shm_swapin_readahead(struct vm_area_struct *vma, +static void shmem_swapin_range(struct vm_area_struct *vma, unsigned long start, unsigned long end, struct address_space *mapping) { XA_STATE(xas, &mapping->i_pages, linear_page_index(vma, start)); - pgoff_t end_index = linear_page_index(vma, end + PAGE_SIZE - 1); + pgoff_t end_index = linear_page_index(vma, end) - 1; struct page *page; struct swap_iocb *splug = NULL; rcu_read_lock(); xas_for_each(&xas, page, end_index) { - swp_entry_t swap; + unsigned long addr; + swp_entry_t entry; if (!xa_is_value(page)) continue; - swap = radix_to_swp_entry(page); + entry = radix_to_swp_entry(page); /* There might be swapin error entries in shmem mapping. */ - if (non_swap_entry(swap)) + if (non_swap_entry(entry)) continue; + + addr = vma->vm_start + + ((xas.xa_index - vma->vm_pgoff) << PAGE_SHIFT); xas_pause(&xas); rcu_read_unlock(); - page = read_swap_cache_async(swap, GFP_HIGHUSER_MOVABLE, - NULL, 0, false, &splug); + page = read_swap_cache_async(entry, mapping_gfp_mask(mapping), + vma, addr, false, &splug); if (page) put_page(page); @@ -266,8 +270,6 @@ static void force_shm_swapin_readahead(struct vm_area_struct *vma, } rcu_read_unlock(); swap_read_unplug(splug); - - lru_add_drain(); /* Push any new pages onto the LRU now */ } #endif /* CONFIG_SWAP */ @@ -291,8 +293,8 @@ static long madvise_willneed(struct vm_area_struct *vma, } if (shmem_mapping(file->f_mapping)) { - force_shm_swapin_readahead(vma, start, end, - file->f_mapping); + shmem_swapin_range(vma, start, end, file->f_mapping); + lru_add_drain(); /* Push any new pages onto the LRU now */ return 0; } #else