From patchwork Mon May 22 05:17:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249782 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 AA5CCC7EE23 for ; Mon, 22 May 2023 05:17:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 255FA6B0074; Mon, 22 May 2023 01:17:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 206946B0075; Mon, 22 May 2023 01:17:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F52F900002; Mon, 22 May 2023 01:17:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 00E556B0074 for ; Mon, 22 May 2023 01:17:35 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C2B041C6C84 for ; Mon, 22 May 2023 05:17:35 +0000 (UTC) X-FDA: 80816733270.30.F48F635 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by imf17.hostedemail.com (Postfix) with ESMTP id EB5D74000A for ; Mon, 22 May 2023 05:17:33 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=f6H5lzyE; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 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=1684732654; 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=Z5tVv9SCeFMWQqxzcOmqyajzFINIUSkZs7h4iNDDH6wCzwJjqpis3QaXA2Q0fbTEFjYLVd 6mA37Tx1tpAOtIYP8ama33EQkpFmt6BAGIVPTMo47vRMksX21HNZR5yRbKpJ2TgAxED9Zc aZqkVHw7DKqdAe0ZYficamZvdGAQzZM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684732654; a=rsa-sha256; cv=none; b=jV+JmbS6ehBwHwfccjSO1asqMJ2ZYOAXt0HwnGS3lzw0QWwPWAxSE7As0lpSWDsTn9hIbu KNpNlnZ071CvLd6illMHLfbQR7cOhTbdwqOztm+joCK/duqHx9GHCTDoyoqQxEw6UtY28K 5v1t27ldSucLcGyVrir2Ol959Om8PQo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=f6H5lzyE; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-561d611668eso71684067b3.0 for ; Sun, 21 May 2023 22:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684732653; x=1687324653; 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=f6H5lzyEl/529vvBXo7cjHFatUfG3YtCbKZO/m7kkdLuuofbAW6JB7TNcMTLxhS2Fa oCscaMoZSrdZFIADmHM3vqeNvKHSfDv45YS3VG0xINc3KnCVeYBUvVx6KUlmN5IVqTQ3 eea7j8ExK19Opvsc5Spx705Pw81qEdSQc02WpxsCt2PFWo+K9ekVeiRw9nrsNx+U4KaQ G9GGOC4mudc6X5o4tr3EZNzo4YmhfN4UtuJyHpWp81+YRZq+yrHLruWf2ZHUJUdTErJk SGxCiEVvSkiDFU5p6ro7GOO7WaLMeSjUeJjhiSiayQPvsPwDptONLF8o1b8tv18mP3Yi FtUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732653; x=1687324653; 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=IYH7krz4SNjqiTGHztgwh8EPyF0IQ9PmYfmKdDAP4JLEcsHMKnGFhAl17IKvLMbs5H zbuJ2mNOm9tp9DGYxsQ3ozZWT5XGcH4zgWrBxAzTuDumlcmPhQg62y8Kt86F9fkwrPDF lQHn2w5WmeaNEbSkfFpITnsO5IxkPe2cGdTnSca4Eg6J8DFL2IxpMWvHKntgJL0NcHph Io2UEUYFrtGBCo2hoFqJHFFebnhrmjupsb9XDbEabYYh2d2uN/qQ+aopW4oa123pwiBR ShBj0vS1gseeAmzc+TQBHeOBQ139Yo5BMEjUkwZZwpuwQ/6At8FlBm7NoH9kEXkiSRpo IPWw== X-Gm-Message-State: AC+VfDwgFJ8SiSxuvCCT24Drbpw0YQDKTerdRA1dFyFXezbjKygPKwjS KwFwkfC8yHcAFwxEpI9d6Z8K+A== X-Google-Smtp-Source: ACHHUZ7HPZHU/c0SUjH6d0BWcOB8eLdBcSfh1g/VsYEO0pbi+eAMTALQvB8Hsf5hIiR7CjUOpnbz8A== X-Received: by 2002:a81:6ec5:0:b0:561:e944:a559 with SMTP id j188-20020a816ec5000000b00561e944a559mr9577004ywc.31.1684732652960; Sun, 21 May 2023 22:17:32 -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 e129-20020a0dc287000000b00545a08184f8sm1818483ywd.136.2023.05.21.22.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:17:32 -0700 (PDT) Date: Sun, 21 May 2023 22:17:29 -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 , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 21/31] mm/madvise: clean up force_shm_swapin_readahead() In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EB5D74000A X-Rspam-User: X-Stat-Signature: d5cmpa1wofpbpuu14m8c51r54oxs7154 X-Rspamd-Server: rspam03 X-HE-Tag: 1684732653-219914 X-HE-Meta: U2FsdGVkX1+asbonAByMK0FABCsBQ34oKCqmHH43YKy0qR04w/KIPZKnzhvJdk4LSR9BCrReaQijZYHLDhV7ll0jcMhqjyRIHfScMeXTkb/93PdXKi7lxO1CNtI9yAT1VGA/eAaUI5wckp308/9BsyymEn/DjzJP1BsKfK6nVPfDMJSW2WEEvxcutsjUUVGyl+W6+NzAcW8M8OmyUFS6b9Jmx/LbDOSE6M6un0HKuaEh79uNABAdAg4RyNugajfnCez0c2h3QSlH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jUOKfj66ys9EGAXT/WnMFyVbM+vm20My7fAFVY7RrZIZerlspIeCKcUSxzp4RTVhlJxrA== 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