From patchwork Wed Feb 17 23:35:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12092599 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.6 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,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 BBFA0C433E0 for ; Wed, 17 Feb 2021 23:36:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 421C364D74 for ; Wed, 17 Feb 2021 23:36:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 421C364D74 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 3DB396B006E; Wed, 17 Feb 2021 18:35:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECD86B0070; Wed, 17 Feb 2021 18:35:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B8466B0071; Wed, 17 Feb 2021 18:35:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 031D46B006E for ; Wed, 17 Feb 2021 18:35:57 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BD61C2478 for ; Wed, 17 Feb 2021 23:35:57 +0000 (UTC) X-FDA: 77829369954.13.B5BB01E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf15.hostedemail.com (Postfix) with ESMTP id BD869A0009D5 for ; Wed, 17 Feb 2021 23:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613604956; 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=IJC/VlIq+91W98xndkPTGEyN7MrILcrOIZFc0zZvO1w=; b=VjEOLRaZcjysqMGZau93OoGuMc1tlX/RTNn1wbV5vrMr6H5QdYC1+tnBIvthtzEnBeq56Y 4kB1nUcDqvF7x7Eu2q035OsdE0gsxpYEpihcFk4nlkEtPI3qX74p3Yw6LdyZtIXF1rmUKX SKuxgpWcr7QoWivjpHbCGBtoYP4kfk8= 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-371-0nrDRXYtMAGwip8ASPosTg-1; Wed, 17 Feb 2021 18:35:53 -0500 X-MC-Unique: 0nrDRXYtMAGwip8ASPosTg-1 Received: by mail-qv1-f70.google.com with SMTP id t18so77991qva.6 for ; Wed, 17 Feb 2021 15:35:52 -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=IJC/VlIq+91W98xndkPTGEyN7MrILcrOIZFc0zZvO1w=; b=GiJzMaLRlcUIExEkR1yb3le/QP2SwCEPuZ6YgJ8Fss+cDAT9snbOoKZkClgcM3dwNv X1EPlEwZbBtNYDSgOM8UTsVTZZGsNRH4V1rlKhDN0YPOxyieuN2tO4qwgj7NrnKPbk96 O5Nlc7cHniB0kkgogp1LqTY07Kf8z373xKl5RKXGSfsGD5ksHRMBPdY/TOfCnf9N3i38 vZom9furekLrD6y184hJFbTYwvNdlniNxCTPcF7sGmTH2J4NJGNMRQ7ym4gGBwA/thxv m2/MwsjGZVgOz577siXpR0UtSBk8DNQNuUn4OQInSsh9m+EEcPOVJoJmxUx6dIOI+PSD y2Ag== X-Gm-Message-State: AOAM532OIpMSquhQe5rmnl1SJnJQvpVhJx8YD6rE8ETfHeIqNUAT9m7S j2528AX2bjgKGfw8CiegHpeEUsS2jdar98T9h6fn1pmOT0fyCimZ/8W9VeW16rdcvuFZ/mNWE9f TIziIV5SoLvCsqsfj3ckX8ja4nrjEBlcN/LXp5Dgi8lqWPHtkKoopRtqsoPVr X-Received: by 2002:a37:a452:: with SMTP id n79mr1749732qke.60.1613604951953; Wed, 17 Feb 2021 15:35:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYXiab+QHsGr+JgkvRch04EDItcq1JEuMGGAgiNB4vHvF7Kqj8vtVYT6KCzNXV5qB6U0d2ww== X-Received: by 2002:a37:a452:: with SMTP id n79mr1749695qke.60.1613604951694; Wed, 17 Feb 2021 15:35:51 -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 o5sm2739622qkh.59.2021.02.17.15.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 15:35:51 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Gal Pressman , Matthew Wilcox , Wei Zhang , peterx@redhat.com, Mike Kravetz , Mike Rapoport , Christoph Hellwig , Andrew Morton , Linus Torvalds , David Gibson , Jason Gunthorpe , Jann Horn , Kirill Tkhai , Kirill Shutemov , Miaohe Lin , Andrea Arcangeli , Jan Kara Subject: [PATCH v5 1/5] hugetlb: Dedup the code to add a new file_region Date: Wed, 17 Feb 2021 18:35:43 -0500 Message-Id: <20210217233547.93892-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217233547.93892-1-peterx@redhat.com> References: <20210217233547.93892-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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BD869A0009D5 X-Stat-Signature: uonhsawamdqt7dana9xu4ddyyys9g8nz Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613604956-413617 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 b6992297aa16..e302ed715839 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -331,6 +331,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. * @@ -346,7 +364,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; @@ -375,18 +393,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; } @@ -394,17 +405,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;