From patchwork Tue Dec 29 04:21:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11991931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BD13C433E0 for ; Tue, 29 Dec 2020 04:21:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD8F520867 for ; Tue, 29 Dec 2020 04:21:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD8F520867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DC0426B0085; Mon, 28 Dec 2020 23:21:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4A358D0018; Mon, 28 Dec 2020 23:21:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3A6C6B0088; Mon, 28 Dec 2020 23:21:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id A9BA46B0085 for ; Mon, 28 Dec 2020 23:21:37 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4A65F1EE6 for ; Tue, 29 Dec 2020 04:21:37 +0000 (UTC) X-FDA: 77645021034.30.cable09_071625e27499 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 2755B180B3AB8 for ; Tue, 29 Dec 2020 04:21:37 +0000 (UTC) X-HE-Tag: cable09_071625e27499 X-Filterd-Recvd-Size: 4321 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Dec 2020 04:21:36 +0000 (UTC) Received: by mail-ed1-f54.google.com with SMTP id c7so11521534edv.6 for ; Mon, 28 Dec 2020 20:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rARSHbe1S26PRkq8+x6cxGijBjBXfiB9lCHLHmc97wE=; b=NddYy4IJRrCm+37jgl1VOxp1GFEsbWbIhhj0JCsxOMkdMTVdqXXNURg6AloieidS/y VRqS6cM8iw0BHPh6uBTiHl3thDSlyZgfN67V+uIAlhzAEZ+iJsqFw4xJZiBBRabO4dqV ok/Xq+7WeFmq6vJEcYIpql8yu+j/uPmC+wHf++oiNljpdDfRf7yf37/7Drf11z47hsrO LoLGRy1TPyIpBI8/+TxBwAIQ3Ww8ANqQrMm3eAxuc7fMzzlcP3zz3GnLvNWtNqxAE9If 38Dw5ELQ3UhkYK463pJDl0VrwadbALY5bP3m9YulDumx2NPnYiYA+K73pAwhRTk45E7b QSsw== 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; bh=rARSHbe1S26PRkq8+x6cxGijBjBXfiB9lCHLHmc97wE=; b=bdUwqJVnvwgO+zswr+0lctGFr31+6u2oGr37VcShJ4Mw3YvZJgRw/8mPV621JBab2g i7BXkVtOH5Pz8DUN34OPpR6HhHzfH1pdOO0IkHvSfj1bgsTh3lz3G1EqmvY7Gb/3iixT +FcP53giuDK6cIW4NcD6qQGDKjHnc7aAWa09zDxBUg3uTbIa9gwUnNEhDlnD7Ku8vJOH R/r195Uhx+dMBf4pyJGAM8+mS4X9/QiQz8Y28US9g8hUjEhkunAnwGXVuCdgaZ5udMZA ySsrbFSDJey+2o9RtC8a1uYgNTV77b7PnqtAFKOU3LrWB9qnGlhPGI1TNmuOB8gh13t8 fKsg== X-Gm-Message-State: AOAM5337ry8LDT7tkQXQZmDerdA/gMu9bIWEGIe69U4EVl5pRcJGzrZ9 YPgd+fHoZFT9AGpNSYdsPFm9o6I75aA= X-Google-Smtp-Source: ABdhPJwlPIRjrX4iiSKz48QZ6l13r+mUU/WatjltS5rwgQ2NZk/Fs9+AucMuEB5YCdijOv334fqQOg== X-Received: by 2002:a50:b246:: with SMTP id o64mr32711818edd.132.1609215695163; Mon, 28 Dec 2020 20:21:35 -0800 (PST) Received: from localhost.localdomain ([2a03:5342:f:6::2]) by smtp.gmail.com with ESMTPSA id r23sm17661199ejd.56.2020.12.28.20.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 20:21:34 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Mike Kravetz , Peter Xu Subject: [PATCH] mm/hugetlb.c: fix unnecessary address expansion of pmd sharing Date: Tue, 29 Dec 2020 12:21:25 +0800 Message-Id: <20201229042125.2663029-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 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 current code would unnecessarily expand the address range. Consider one example, (start, end) = (1G-2M, 3G+2M), and (vm_start, vm_end) = (1G-4M, 3G+4M), the expected adjustment should be keep (1G-2M, 3G+2M) without expand. But the current result will be (1G-4M, 3G+4M). Actually, the range (1G-4M, 1G) and (3G, 3G+4M) would never been involved in pmd sharing. After this patch, if pud aligned *start across vm_start, then we know the *start and vm_start are in same pud_index, and vm_start is not pud aligned, so don't adjust *start. Same logic applied to *end. Fixes: commit 75802ca66354 ("mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible") Cc: Mike Kravetz Cc: Peter Xu Signed-off-by: Li Xinhai Reviewed-by: Mike Kravetz Reviewed-by: Peter Xu Reviewed-by: Li Xinhai --- mm/hugetlb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cbf32d2824fd..d1e9ea55b7e6 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5249,11 +5249,16 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, a_end = ALIGN(*end, PUD_SIZE); /* - * Intersect the range with the vma range, since pmd sharing won't be - * across vma after all + * If the PUD aligned address across vma range, then it means the + * vm_start/vm_end is not PUD aligned. In that case, we must don't + * adjust range because pmd sharing is not possbile at the start and/or + * end part of vma. */ - *start = max(vma->vm_start, a_start); - *end = min(vma->vm_end, a_end); + if (a_start >= vma->vm_start) + *start = a_start; + + if (a_end <= vma->vm_end) + *end = a_end; } /*