From patchwork Mon Oct 26 14:51:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11857477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C09FB92C for ; Mon, 26 Oct 2020 14:54:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E9A622263 for ; Mon, 26 Oct 2020 14:54:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="cD6rCx5J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E9A622263 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 98A726B0073; Mon, 26 Oct 2020 10:54:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 93A476B0083; Mon, 26 Oct 2020 10:54:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DC796B0085; Mon, 26 Oct 2020 10:54:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 4F7016B0073 for ; Mon, 26 Oct 2020 10:54:48 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DD648180AD81D for ; Mon, 26 Oct 2020 14:54:47 +0000 (UTC) X-FDA: 77414373414.25.rate97_1f0874727274 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id B079F1804E3A9 for ; Mon, 26 Oct 2020 14:54:47 +0000 (UTC) X-Spam-Summary: 1,0,0,3fd37e98ae638e3c,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:69:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3865:3867:3868:4119:4321:4385:4605:5007:6119:6261:6653:6737:6738:7875:9010:9036:9592:10004:11026:11473:11658:11914:12043:12048:12114:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13161:13229:13894:14096:14110:14181:14394:14721:21080:21444:21451:21627:21990:30012:30054,0,RBL:209.85.214.193:@bytedance.com:.lbl8.mailshell.net-66.100.201.201 62.2.0.100;04yfnwwqaitdtpc7jwifagpn7dw57ypbhforowmnab9kjw46ehrjctzi7jcnuez.upggszd95kdbx7gncwtqksdpk6nunppefk4q7ajjf8n4csjk5zg3s3qu543jz7x.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: rate97_1f0874727274 X-Filterd-Recvd-Size: 8134 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 14:54:47 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id b12so2497834plr.4 for ; Mon, 26 Oct 2020 07:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nBOWUvI64CVkddhS0ymba6FNm4rZpN25m+YjytIcpHw=; b=cD6rCx5J9AHr93YCMUekQ1zaeA2YYNgJOjsT/ihum6qcydD4HzFe/+LBspsS8mcD0p +FZ5UwCLhtYy7eiTgUSBWE6LX3Ns3so2GmPf2QtOBAk2R7FbELeJ1tznikTj7mBgL4D2 EsIGG4PSQ+CuJm2EElGrm234AKZW4HN1SAsfIiwkXbhcSR56tEbBwbUfiM2p7LF6/T5n F6UKOeoO5EnJmTznuesW+ll0Mk9khtUOmOfXm9n673P040oyAAcVmLeD2Ei5vhT9Mba6 PEILq0tdaVGTilpvKBpJFye27FzINR/kVCZ/H2p4ddBqQFaA+bjEQdt04myqJcrEe9XW Bv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nBOWUvI64CVkddhS0ymba6FNm4rZpN25m+YjytIcpHw=; b=ioqNVD6Xx/xa+WdxJrVMksWiP6C8KdbyborAt8WOEoZ/FEScEduLtAWeG64Oz71sjY un0+6geDLwzWtTiWUDuRZJT/KvhRDy2rdFNXufuuL8xMbOJ9Anfta5YWPPp+8XznCbMi es+mh728Fk7d2BTE/L9y0oqWvuY0i4w9KIdNgrpLLMi0IHs79CJYgyl6bqgE8vR5Igt4 jgNJaiKRs77egU0bosP24iAKyOgoTn/JPq1anXBG/KnwUM+QyfCxA08U/3tV3+39S7MQ ICt8J8l61g1i1Naw7JV11uT3X3VNRivCCyix3eQ34n05jBW+04lS+BEDmGqRARucYjYe icJg== X-Gm-Message-State: AOAM530PWq1yXYD+Y92lY5IFrc0EhC69MINmstAJTynCEfJcoakyglyX xaMH2Dpl50/bl4Ne+LnnqSE++A== X-Google-Smtp-Source: ABdhPJwaHtkSuog973zfhn2PNnZUpQnIFVl1BNtXohx04K2a0S87z8ygehWrmiJg5l0SnkpyhpEcHw== X-Received: by 2002:a17:90a:9206:: with SMTP id m6mr21586890pjo.42.1603724086406; Mon, 26 Oct 2020 07:54:46 -0700 (PDT) Received: from localhost.localdomain ([103.136.220.89]) by smtp.gmail.com with ESMTPSA id x123sm12042726pfb.212.2020.10.26.07.54.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2020 07:54:45 -0700 (PDT) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song Subject: [PATCH v2 10/19] mm/hugetlb: Introduce remap_huge_page_pmd_vmemmap helper Date: Mon, 26 Oct 2020 22:51:05 +0800 Message-Id: <20201026145114.59424-11-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201026145114.59424-1-songmuchun@bytedance.com> References: <20201026145114.59424-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: The __free_huge_page_pmd_vmemmap and __remap_huge_page_pmd_vmemmap are almost the same code. So introduce remap_free_huge_page_pmd_vmemmap helper to simplify the code. Signed-off-by: Muchun Song --- mm/hugetlb.c | 98 +++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 59 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cea580058a16..bd0c4e7fd994 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1482,6 +1482,41 @@ static inline int freed_vmemmap_hpage_dec(struct page *page) return atomic_dec_return_relaxed(&page->_mapcount) + 1; } +typedef void (*remap_pte_fn)(struct page *reuse, pte_t *ptep, + unsigned long start, unsigned int nr_pages, + struct list_head *pages); + +static void remap_huge_page_pmd_vmemmap(struct hstate *h, pmd_t *pmd, + unsigned long addr, + struct list_head *pages, + remap_pte_fn remap_fn) +{ + unsigned long next; + unsigned long start = addr + RESERVE_VMEMMAP_SIZE; + unsigned long end = addr + nr_vmemmap_size(h); + struct page *reuse = NULL; + + flush_cache_vunmap(start, end); + + addr = start; + do { + unsigned int nr_pages; + pte_t *ptep; + + ptep = pte_offset_kernel(pmd, addr); + if (!reuse) { + reuse = pte_page(ptep[-1]); + set_page_private(reuse, addr - PAGE_SIZE); + } + + next = vmemmap_hpage_addr_end(addr, end); + nr_pages = (next - addr) >> PAGE_SHIFT; + remap_fn(reuse, ptep, addr, nr_pages, pages); + } while (pmd++, addr = next, addr != end); + + flush_tlb_kernel_range(start, end); +} + static inline void free_vmemmap_page_list(struct list_head *list) { struct page *page, *next; @@ -1513,33 +1548,6 @@ static void __free_huge_page_pte_vmemmap(struct page *reuse, pte_t *ptep, } } -static void __free_huge_page_pmd_vmemmap(struct hstate *h, pmd_t *pmd, - unsigned long addr, - struct list_head *free_pages) -{ - unsigned long next; - unsigned long start = addr + RESERVE_VMEMMAP_NR * PAGE_SIZE; - unsigned long end = addr + nr_vmemmap_size(h); - struct page *reuse = NULL; - - addr = start; - do { - unsigned int nr_pages; - pte_t *ptep; - - ptep = pte_offset_kernel(pmd, addr); - if (!reuse) - reuse = pte_page(ptep[-1]); - - next = vmemmap_hpage_addr_end(addr, end); - nr_pages = (next - addr) >> PAGE_SHIFT; - __free_huge_page_pte_vmemmap(reuse, ptep, addr, nr_pages, - free_pages); - } while (pmd++, addr = next, addr != end); - - flush_tlb_kernel_range(start, end); -} - static void split_vmemmap_pmd(pmd_t *pmd, pte_t *pte_p, unsigned long addr) { struct mm_struct *mm = &init_mm; @@ -1598,7 +1606,8 @@ static void free_huge_page_vmemmap(struct hstate *h, struct page *head) split_vmemmap_huge_page(head, pmd); } - __free_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &free_pages); + remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &free_pages, + __free_huge_page_pte_vmemmap); freed_vmemmap_hpage_inc(pmd_page(*pmd)); spin_unlock(ptl); @@ -1638,35 +1647,6 @@ static void __remap_huge_page_pte_vmemmap(struct page *reuse, pte_t *ptep, } } -static void __remap_huge_page_pmd_vmemmap(struct hstate *h, pmd_t *pmd, - unsigned long addr, - struct list_head *remap_pages) -{ - unsigned long next; - unsigned long start = addr + RESERVE_VMEMMAP_NR * PAGE_SIZE; - unsigned long end = addr + nr_vmemmap_size(h); - struct page *reuse = NULL; - - addr = start; - do { - unsigned int nr_pages; - pte_t *ptep; - - ptep = pte_offset_kernel(pmd, addr); - if (!reuse) { - reuse = pte_page(ptep[-1]); - set_page_private(reuse, addr - PAGE_SIZE); - } - - next = vmemmap_hpage_addr_end(addr, end); - nr_pages = (next - addr) >> PAGE_SHIFT; - __remap_huge_page_pte_vmemmap(reuse, ptep, addr, nr_pages, - remap_pages); - } while (pmd++, addr = next, addr != end); - - flush_tlb_kernel_range(start, end); -} - static inline void alloc_vmemmap_pages(struct hstate *h, struct list_head *list) { int i; @@ -1695,8 +1675,8 @@ static void alloc_huge_page_vmemmap(struct hstate *h, struct page *head) ptl = vmemmap_pmd_lockptr(pmd); spin_lock(ptl); - __remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, - &remap_pages); + remap_huge_page_pmd_vmemmap(h, pmd, (unsigned long)head, &remap_pages, + __remap_huge_page_pte_vmemmap); if (!freed_vmemmap_hpage_dec(pmd_page(*pmd))) { /* * Todo: