From mboxrd@z Thu Jan 1 00:00:00 1970 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 5AFAEC5479D for ; Wed, 11 Jan 2023 14:29:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 666E18E000B; Wed, 11 Jan 2023 09:29:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55797900002; Wed, 11 Jan 2023 09:29:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13AD68E0001; Wed, 11 Jan 2023 09:29:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EFE8E8E0002 for ; Wed, 11 Jan 2023 09:29:08 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C24501401EF for ; Wed, 11 Jan 2023 14:29:08 +0000 (UTC) X-FDA: 80342750376.16.5031402 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id D009DC0019 for ; Wed, 11 Jan 2023 14:29:06 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="J8+3C/3v"; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673447347; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=smKdNZSEfoOItNhulwcaWNs98KWqjgVXzV6tgn0lCxw=; b=HiXADWqYMceO7embY/ZBkJuwhvOnyLuySOIRw5xv8Tom6RYztMft73Ne08fOCmk2O7Wm8o fAMo/SZk9xHH4RWiDtnpGgJwyYYWdGR2bSNfv7auX3e9lMUp84m0IFAk/sj7LhV85FT1HW 5Qjqt/Nn7/SM37yvbAqxnC3XiRGKkv8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="J8+3C/3v"; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673447347; a=rsa-sha256; cv=none; b=1dUJl/WXnsdSuUvY7kAP8GDTiTBcK4joWKLwnMmN2XWeM2/fiKdpvHcMInppoQ8w0baDOu Kx/pZX6ssO7njHNAjYll1mb1GSg3twu/O1+kacb0UNlvv7Wj3wD9NRXox9xmkS1+sU1L9j uONNiufiyCycKfTr2Y6OQXyyaG8Q/uI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=smKdNZSEfoOItNhulwcaWNs98KWqjgVXzV6tgn0lCxw=; b=J8+3C/3vUG9uR+wRCdJx0v3GEa ZKmbcIu3wxmkU9Xs08G09aHfo5gTcgtVYWg7OHkWiLtOCMuFg2qMVhzgkPLTsIM/17sg+EFZ35GiM nYFRThMprqAxwGLbIAzPQ+6p0tzPpQOC3MaswYu0/omVEldSBeEX5dHFrbRsRt+s7xfCEdLfCKzfY bQaIvCEUIaIXvmNQ3vnmPGkIQKgvag2GelzxGrdgp67J3B+Ynk+V8UZOKS0eaJ7qwwyDBEsRGR+Cs tWZYUuYFfH7f/G3YCJflBZFUU3ku8kEL2nL38WP/EDHQl/hY0RXkwQqtjUlzMjW8uiQHW66XPGAig ZdIHaSSA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFc6P-004CYN-M4; Wed, 11 Jan 2023 14:29:17 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Hugh Dickins Subject: [PATCH 08/28] mm: Add folio_add_new_anon_rmap() Date: Wed, 11 Jan 2023 14:28:54 +0000 Message-Id: <20230111142915.1001531-9-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230111142915.1001531-1-willy@infradead.org> References: <20230111142915.1001531-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D009DC0019 X-Stat-Signature: akz81ys6irdup6aosm8syc4xtsxybtmc X-HE-Tag: 1673447346-194789 X-HE-Meta: U2FsdGVkX19/ld0dEoNQBQ28EHMEheLFENr/LRGfP1XoIYoEC88RnO/fNhfZsts8Dw8WZvrHxaAdupES03Gsbm4XfTos6UUMZSdhucSjuCUNj2Dod89syNuemegvjAUYjfGz3lzUwWpLNoIhOqVR99ALERpfJKn0rqAbbKGVVA0xegyTr3QxeQYmg9M8mmgRPPmiYwJB+y8OAUe2o9Iu8xu1iwpvY74I3BQ83AkktDpn0Ffckh61TfcfMX9t78DDZBv+XwKzT8Qh6f8k0J7OS/AP+Yu597UggKJXqJV0lKHDDSZdYFaHFP0W5mM6NYXBK1NNmFaqmvVemzPgjesoHaE2nYX3Y0AJsmsCHA7GSjsdKYZ2ugxQNrncWzfG7UhsdY3+8QlCpxur+wBbf00GzfqiAGsk/bcHa2Xts/42K4PnnTz6vyu0/MCnDjV4Se+5dCseU2ERWjQHCNtyJ+GRWLBdmtMMsJAOMJrdqjzZnaxX2jLEMVAdsbXsnRQgDGJwuIySHIhAvwxZ5zX6WkXaL9sqPIluMX+SqOimSfM2S+h55XFby04gVHKq6gsRjPLRi/awAB6zVqV55jkSyzuNcG9As22SxMBsDzdYc4Pjzfz/341UOp6N1SbynXKWsWj8Y153i23gOd+y3s+4IjKZX0FW8aT48RvHN/k7m7vwq/Id572dPmmRwmekgFFPtmhCRC9bne+Whw3snelFSziJ4fSiKA4IDwdZlbu7OmDVeqRjCGkT6kO0pppsFhZUgNGuPEeInv+nzmdxG+27V0o4ResXvGgOYjhNtoMjCN2mlPmzKyCPpp72lBkaYlw6MUvcFqIVwcDoRgC9m/VTcSS9GEP65eGhFZTw8MA2FjZWedd4E0/nZ0Ht/rPXysXYLFv85GZsNJargaZGwglF4ySYuLR6znss+FmVKzmH6kOh3vGtLsJxgXppkA== 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: In contrast to other rmap functions, page_add_new_anon_rmap() is always called with a freshly allocated page. That means it can't be called with a tail page. Turn page_add_new_anon_rmap() into folio_add_new_anon_rmap() and add a page_add_new_anon_rmap() wrapper. Callers can be converted individually. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/rmap.h | 2 ++ mm/folio-compat.c | 8 ++++++++ mm/rmap.c | 37 ++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index bd3504d11b15..aa682a2a93ce 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -194,6 +194,8 @@ void page_add_anon_rmap(struct page *, struct vm_area_struct *, unsigned long address, rmap_t flags); void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, unsigned long address); +void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, + unsigned long address); void page_add_file_rmap(struct page *, struct vm_area_struct *, bool compound); void page_remove_rmap(struct page *, struct vm_area_struct *, diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 69ed25790c68..92f53adc0dd9 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -123,3 +123,11 @@ void putback_lru_page(struct page *page) { folio_putback_lru(page_folio(page)); } + +void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma, + unsigned long address) +{ + VM_BUG_ON_PAGE(PageTail(page), page); + + return folio_add_new_anon_rmap((struct folio *)page, vma, address); +} diff --git a/mm/rmap.c b/mm/rmap.c index 7b83b56d5603..2749e1466b09 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1264,41 +1264,40 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, } /** - * page_add_new_anon_rmap - add mapping to a new anonymous page - * @page: the page to add the mapping to + * folio_add_new_anon_rmap - Add mapping to a new anonymous folio. + * @folio: The folio to add the mapping to. * @vma: the vm area in which the mapping is added * @address: the user virtual address mapped * - * If it's a compound page, it is accounted as a compound page. As the page - * is new, it's assume to get mapped exclusively by a single process. - * - * Same as page_add_anon_rmap but must only be called on *new* pages. + * Like page_add_anon_rmap() but must only be called on *new* folios. * This means the inc-and-test can be bypassed. - * Page does not have to be locked. + * The folio does not have to be locked. + * + * If the folio is large, it is accounted as a THP. As the folio + * is new, it's assumed to be mapped exclusively by a single process. */ -void page_add_new_anon_rmap(struct page *page, - struct vm_area_struct *vma, unsigned long address) +void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, + unsigned long address) { int nr; VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma); - __SetPageSwapBacked(page); + __folio_set_swapbacked(folio); - if (likely(!PageCompound(page))) { + if (likely(!folio_test_pmd_mappable(folio))) { /* increment count (starts at -1) */ - atomic_set(&page->_mapcount, 0); + atomic_set(&folio->_mapcount, 0); nr = 1; } else { - VM_BUG_ON_PAGE(!PageTransHuge(page), page); /* increment count (starts at -1) */ - atomic_set(compound_mapcount_ptr(page), 0); - atomic_set(subpages_mapcount_ptr(page), COMPOUND_MAPPED); - nr = thp_nr_pages(page); - __mod_lruvec_page_state(page, NR_ANON_THPS, nr); + atomic_set(&folio->_entire_mapcount, 0); + atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED); + nr = folio_nr_pages(folio); + __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr); } - __mod_lruvec_page_state(page, NR_ANON_MAPPED, nr); - __page_set_anon_rmap(page, vma, address, 1); + __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); + __page_set_anon_rmap(&folio->page, vma, address, 1); } /** -- 2.35.1