From patchwork Thu May 24 00:58:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10422555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B4966032C for ; Thu, 24 May 2018 01:00:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 190AE292EA for ; Thu, 24 May 2018 01:00:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D898292EC; Thu, 24 May 2018 01:00:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 578A2292EA for ; Thu, 24 May 2018 01:00:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FA776B0269; Wed, 23 May 2018 21:00:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4581C6B026A; Wed, 23 May 2018 21:00:38 -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 371796B026B; Wed, 23 May 2018 21:00:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id E40046B0269 for ; Wed, 23 May 2018 21:00:37 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id x2-v6so15224425plv.0 for ; Wed, 23 May 2018 18:00:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=4/rGQIY64SAvlWsN3YnnVI47/qixjCV80/hmpjm+fno=; b=TbjvGzGOJRH80U/8OFhgoRBdFqrMZQvKJvMqyba+RVYJUyZlS2GsDvUbvqnGQJyWsA OUcw3xEKSbyEtnfX464tdZTQHf32SSg4c4Q/Wtr/THFC3T2fabrO+W/9xe7xcZZapZvW rKoSNudFM7f9CIsMjAszy9Caev3T3AovsQJc4nLaTSpIW1hty7iz84VDwuPjj8tPSYar NI7/yXZbQLszxI4CJQfCjZIkaYRpTj9+JImKhKr6acjdguLnr4BjWJG035ByesFykl2i uADnox4pJjsidTlMUy+NvypcbQvWRzZabWyA2wvepR6dMM2H0rvBDfoFrNMrPBRLUO/x LfnQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ALKqPwew4v8KyesXVZTianwkh/3MTjOaH5JJ9sennCpHx9yzjPvbay37 vqBy2Vb4ka/dVVEwBFv/tGiOSOpCqgalqN1t868bQQ8UKMRa2UF/Qb4bzgYLGzgURDH8jaGEbBe jx93ONZuQcYEQX6PNgSxj20jLhROhfC3s2SrXqiZfPXO6H7II/ER3AT+GnbffC4nbNg== X-Received: by 2002:a17:902:bccc:: with SMTP id o12-v6mr5123306pls.56.1527123637583; Wed, 23 May 2018 18:00:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqXXfUjwy3w6yA9m0jQsgMEwobQKBjj7mxFl+cvsxu5Xx3+f+sVzhj9Ia+2x7diZVYpJyKO X-Received: by 2002:a17:902:bccc:: with SMTP id o12-v6mr5123239pls.56.1527123636516; Wed, 23 May 2018 18:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527123636; cv=none; d=google.com; s=arc-20160816; b=zemtvBXmWjxb5WCuz/Vn/+J5hBYOtN+uJRaXjtxQnNLigsn9NrNPlIiSTC9kw1ynvu xIFSccRtaPAS4F3hHR9Vf7PXdwb8n/aAh8lhdcg5FqEOSumic/E9JEohhMjBlHaF4wpO ujnmWtsVEt9h70DSenMdUuevAP+/br6cqkcJ8GifWKQU4JZejz6XIKlLyPTutTWYn48V yda70lrlR1neo2YLEIxyMSRS4H5mdc5bnlD7aceZoVfFHGv6g53dbsw5Z4JcOK4Al4BU K5ca39Kb2CekeFa+BL7JMhHp/2nb05RMiVxIGV/WCjO0PDKLSSpPsCAuAXjknlipSp5w zOEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4/rGQIY64SAvlWsN3YnnVI47/qixjCV80/hmpjm+fno=; b=Ev2wdnUN1sWjRRJ8rza5F+Tkl9/zOMTRfvBbo9Aed1XEPiq0wAvm8SDL2D5E52i06o SoHoMUYYGwpGzf+ymcEFdvyOScWevZLATSnD1wNosCA5T0QSwV553sVXfLtNMypqT7pC XxZro2LDcABzSqWWixYEa/VINDjDe5fkrKF+zxGKbSuyVUwHZ1F3TDUvDWUZ1dlSEWOM CXafy02DbWXLhdQ7Qn2y0FqM278ABi+bgD+I5X9LAJe6lDM0WIyJahIofGXKlSGFMDKm oOU863bdN25FtQE5YdixbkiHO8+cYTDQyyqigvhp3eNijl5hft5ZazlePA+KP+vD1A7R kPNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id o1-v6si19635860pld.424.2018.05.23.18.00.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 18:00:36 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 18:00:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,435,1520924400"; d="scan'208";a="42362557" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga008.fm.intel.com with ESMTP; 23 May 2018 18:00:33 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , David Rientjes , Andrea Arcangeli , "Kirill A. Shutemov" , Andi Kleen , Jan Kara , Matthew Wilcox , Hugh Dickins , Minchan Kim , Shaohua Li , Christopher Lameter , "Aneesh Kumar K.V" , Punit Agrawal , Anshuman Khandual , Mike Kravetz , Michal Hocko Subject: [PATCH -V2 -mm 3/4] mm, hugetlbfs: Rename address to haddr in hugetlb_cow() Date: Thu, 24 May 2018 08:58:50 +0800 Message-Id: <20180524005851.4079-4-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180524005851.4079-1-ying.huang@intel.com> References: <20180524005851.4079-1-ying.huang@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Huang Ying To take better advantage of general huge page copying optimization, the target subpage address will be passed to hugetlb_cow(), then copy_user_huge_page(). So we will use both target subpage address and huge page size aligned address in hugetlb_cow(). To distinguish between them, "haddr" is used for huge page size aligned address to be consistent with Transparent Huge Page naming convention. Now, only huge page size aligned address is used in hugetlb_cow(), so the "address" is renamed to "haddr" in hugetlb_cow() in this patch. Next patch will use target subpage address in hugetlb_cow() too. The patch is just code cleanup without any functionality changes. Signed-off-by: "Huang, Ying" Suggested-by: Mike Kravetz Suggested-by: Michal Hocko Cc: David Rientjes Cc: Andrea Arcangeli Cc: "Kirill A. Shutemov" Cc: Andi Kleen Cc: Jan Kara Cc: Matthew Wilcox Cc: Hugh Dickins Cc: Minchan Kim Cc: Shaohua Li Cc: Christopher Lameter Cc: "Aneesh Kumar K.V" Cc: Punit Agrawal Cc: Anshuman Khandual Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 696befffe6f7..ad3bec2ed269 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3500,7 +3500,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, * Keep the pte_same checks anyway to make transition from the mutex easier. */ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long address, pte_t *ptep, + unsigned long haddr, pte_t *ptep, struct page *pagecache_page, spinlock_t *ptl) { pte_t pte; @@ -3518,7 +3518,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, * and just make the page writable */ if (page_mapcount(old_page) == 1 && PageAnon(old_page)) { page_move_anon_rmap(old_page, vma); - set_huge_ptep_writable(vma, address, ptep); + set_huge_ptep_writable(vma, haddr, ptep); return 0; } @@ -3542,7 +3542,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, * be acquired again before returning to the caller, as expected. */ spin_unlock(ptl); - new_page = alloc_huge_page(vma, address, outside_reserve); + new_page = alloc_huge_page(vma, haddr, outside_reserve); if (IS_ERR(new_page)) { /* @@ -3555,11 +3555,10 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, if (outside_reserve) { put_page(old_page); BUG_ON(huge_pte_none(pte)); - unmap_ref_private(mm, vma, old_page, address); + unmap_ref_private(mm, vma, old_page, haddr); BUG_ON(huge_pte_none(pte)); spin_lock(ptl); - ptep = huge_pte_offset(mm, address & huge_page_mask(h), - huge_page_size(h)); + ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); if (likely(ptep && pte_same(huge_ptep_get(ptep), pte))) goto retry_avoidcopy; @@ -3584,12 +3583,12 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, goto out_release_all; } - copy_user_huge_page(new_page, old_page, address, vma, + copy_user_huge_page(new_page, old_page, haddr, vma, pages_per_huge_page(h)); __SetPageUptodate(new_page); set_page_huge_active(new_page); - mmun_start = address & huge_page_mask(h); + mmun_start = haddr; mmun_end = mmun_start + huge_page_size(h); mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end); @@ -3598,25 +3597,24 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, * before the page tables are altered */ spin_lock(ptl); - ptep = huge_pte_offset(mm, address & huge_page_mask(h), - huge_page_size(h)); + ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); if (likely(ptep && pte_same(huge_ptep_get(ptep), pte))) { ClearPagePrivate(new_page); /* Break COW */ - huge_ptep_clear_flush(vma, address, ptep); + huge_ptep_clear_flush(vma, haddr, ptep); mmu_notifier_invalidate_range(mm, mmun_start, mmun_end); - set_huge_pte_at(mm, address, ptep, + set_huge_pte_at(mm, haddr, ptep, make_huge_pte(vma, new_page, 1)); page_remove_rmap(old_page, true); - hugepage_add_new_anon_rmap(new_page, vma, address); + hugepage_add_new_anon_rmap(new_page, vma, haddr); /* Make the old page be freed below */ new_page = old_page; } spin_unlock(ptl); mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end); out_release_all: - restore_reserve_on_error(h, vma, address, new_page); + restore_reserve_on_error(h, vma, haddr, new_page); put_page(new_page); out_release_old: put_page(old_page);