From patchwork Thu Feb 4 14:50:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12067469 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 006FCC433DB for ; Thu, 4 Feb 2021 14:50:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 615C264F5E for ; Thu, 4 Feb 2021 14:50:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 615C264F5E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BD2626B0006; Thu, 4 Feb 2021 09:50:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BAAFB6B006C; Thu, 4 Feb 2021 09:50:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC0056B0070; Thu, 4 Feb 2021 09:50:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 9709A6B0006 for ; Thu, 4 Feb 2021 09:50:41 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 46186180AD820 for ; Thu, 4 Feb 2021 14:50:41 +0000 (UTC) X-FDA: 77780871882.23.spot49_140abd5275dd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id F339F37606 for ; Thu, 4 Feb 2021 14:50:40 +0000 (UTC) X-HE-Tag: spot49_140abd5275dd X-Filterd-Recvd-Size: 7315 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 14:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612450239; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w7jRvMA4HBy1aAj/yC80X2PETreSK76wGUdXXk+MGi4=; b=Wd08ZBICHukiZuUqZm00PZ3FAO0zDQ16KRG6tD71/tCtr2FhCbTOnK38cJwlEzGSY0NmfU ZoCVsEPJ1L/jvUz8FKKGAXZj9vZUBfsREA54NeIusGDHlKURvbs7zB7PIBFj/XfwR2C8u9 g8+SGAx3AGe6bJ5i8Y+SJTXkooLxUlY= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-iNsKpJguPv23JDqdwtHfJw-1; Thu, 04 Feb 2021 09:50:38 -0500 X-MC-Unique: iNsKpJguPv23JDqdwtHfJw-1 Received: by mail-qv1-f70.google.com with SMTP id v1so2376404qvb.2 for ; Thu, 04 Feb 2021 06:50:38 -0800 (PST) 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=w7jRvMA4HBy1aAj/yC80X2PETreSK76wGUdXXk+MGi4=; b=oB5t+667fqiGhBtugjOhAB1n36+I5BD7dKMnnkgxIZgIBiyAimRn3opL3SpryFnxb9 BYMrktPK1GMBeAMpfpLjn7TVHp08+y+YFbOV31tgJo/ptqGMflGjsdfX2A6O1cSAKDCB cElcEdTnIuGMcDr3MtCaje/GO4VBA+hF6NyDFyL9YvQE7higjmTw0BEYU7ELer270WQ7 A6mQI42KYiFdt6yLwU1FYd43tYvfPygZtxwMHLAnClpy6y0pQHTC2LwV+/etmzglVt1G 0KJwkvdkS1VLS2jbQfyebaGWeePv+7WuQj4/lMpYXO9AJE1SfsNQKailRmShtroN1ocD ocpw== X-Gm-Message-State: AOAM531xgPdtQfNBdUfPDMJSsLvFaJNBzgjarHo87ZRuUXJ/fqz74bwz TYZXniYeOvoZz9t6H63hsndx6qrZD1g8c8VvH4b0VyKjyXiuPJzvikWzQD9xX7Q7Sn357mqtKdZ CTmusarsGLFPvtbrllnOwkyBy0y7DQnD4jX/GE6IM+Pxf2enI16S8nWEcKHAg X-Received: by 2002:ac8:6d2:: with SMTP id j18mr2156539qth.214.1612450237718; Thu, 04 Feb 2021 06:50:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzER/i1DvUdHrf1GPiOThk9/cqRKFwCL/S/o8WFC1+MtPN7xx83suFHqdyMHA+4tPyflgLFFg== X-Received: by 2002:ac8:6d2:: with SMTP id j18mr2156499qth.214.1612450237441; Thu, 04 Feb 2021 06:50:37 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-20-174-93-89-182.dsl.bell.ca. [174.93.89.182]) by smtp.gmail.com with ESMTPSA id e14sm4697589qte.18.2021.02.04.06.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 06:50:36 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kirill Shutemov , Wei Zhang , Mike Rapoport , Matthew Wilcox , Miaohe Lin , Andrea Arcangeli , peterx@redhat.com, Gal Pressman , Jan Kara , Jann Horn , Andrew Morton , Kirill Tkhai , Linus Torvalds , Mike Kravetz , Jason Gunthorpe , David Gibson , Christoph Hellwig Subject: [PATCH v2 1/4] hugetlb: Dedup the code to add a new file_region Date: Thu, 4 Feb 2021 09:50:30 -0500 Message-Id: <20210204145033.136755-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210204145033.136755-1-peterx@redhat.com> References: <20210204145033.136755-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.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: Introduce hugetlb_resv_map_add() helper to add a new file_region rather than duplication the similar code twice in add_reservation_in_range(). Reviewed-by: Mike Kravetz Reviewed-by: Miaohe Lin Signed-off-by: Peter Xu --- mm/hugetlb.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 18f6ee317900..d2859c2aecc9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -321,6 +321,24 @@ static void coalesce_file_region(struct resv_map *resv, struct file_region *rg) } } +static inline long +hugetlb_resv_map_add(struct resv_map *map, struct file_region *rg, long from, + long to, struct hstate *h, struct hugetlb_cgroup *cg, + long *regions_needed) +{ + struct file_region *nrg; + + if (!regions_needed) { + nrg = get_file_region_entry_from_cache(map, from, to); + record_hugetlb_cgroup_uncharge_info(cg, h, map, nrg); + list_add(&nrg->link, rg->link.prev); + coalesce_file_region(map, nrg); + } else + *regions_needed += 1; + + return to - from; +} + /* * Must be called with resv->lock held. * @@ -336,7 +354,7 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, long add = 0; struct list_head *head = &resv->regions; long last_accounted_offset = f; - struct file_region *rg = NULL, *trg = NULL, *nrg = NULL; + struct file_region *rg = NULL, *trg = NULL; if (regions_needed) *regions_needed = 0; @@ -365,18 +383,11 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, /* Add an entry for last_accounted_offset -> rg->from, and * update last_accounted_offset. */ - if (rg->from > last_accounted_offset) { - add += rg->from - last_accounted_offset; - if (!regions_needed) { - nrg = get_file_region_entry_from_cache( - resv, last_accounted_offset, rg->from); - record_hugetlb_cgroup_uncharge_info(h_cg, h, - resv, nrg); - list_add(&nrg->link, rg->link.prev); - coalesce_file_region(resv, nrg); - } else - *regions_needed += 1; - } + if (rg->from > last_accounted_offset) + add += hugetlb_resv_map_add(resv, rg, + last_accounted_offset, + rg->from, h, h_cg, + regions_needed); last_accounted_offset = rg->to; } @@ -384,17 +395,9 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, /* Handle the case where our range extends beyond * last_accounted_offset. */ - if (last_accounted_offset < t) { - add += t - last_accounted_offset; - if (!regions_needed) { - nrg = get_file_region_entry_from_cache( - resv, last_accounted_offset, t); - record_hugetlb_cgroup_uncharge_info(h_cg, h, resv, nrg); - list_add(&nrg->link, rg->link.prev); - coalesce_file_region(resv, nrg); - } else - *regions_needed += 1; - } + if (last_accounted_offset < t) + add += hugetlb_resv_map_add(resv, rg, last_accounted_offset, + t, h, h_cg, regions_needed); VM_BUG_ON(add < 0); return add;