From patchwork Tue Feb 9 03:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12077093 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 58BC2C433E0 for ; Tue, 9 Feb 2021 03:02:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D774E64E9D for ; Tue, 9 Feb 2021 03:02:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D774E64E9D 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 64E226B006C; Mon, 8 Feb 2021 22:02:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 601208D0003; Mon, 8 Feb 2021 22:02:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47CE48D0002; Mon, 8 Feb 2021 22:02:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 297526B006C for ; Mon, 8 Feb 2021 22:02:38 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ED9BA824805A for ; Tue, 9 Feb 2021 03:02:37 +0000 (UTC) X-FDA: 77797231554.18.ghost59_3c12be727603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id D096B100EDBE8 for ; Tue, 9 Feb 2021 03:02:37 +0000 (UTC) X-HE-Tag: ghost59_3c12be727603 X-Filterd-Recvd-Size: 7315 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 03:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612839756; 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=tR/UuXaqBaROltUbV2RDYpoyLXOK1N4qjZ6UzYcMHb0=; b=CHC/1F3HrammfUpdUB7R3DEjtwSO6j1v3IchYVEOZiQuJKHUz03LJqTHDZFIE0AHHrvfZ7 Wk2lkjm5P5ep2IVS8spk96GU7bATWLjgKxnWRRPhHZgQrj4onwF0nxzsIe+Njr0yX2fuRX i9lOFeAlK2emnSMg8n9akE/mlxA1adQ= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-REtwhMZuOG6bE5kl8jUlsw-1; Mon, 08 Feb 2021 22:02:35 -0500 X-MC-Unique: REtwhMZuOG6bE5kl8jUlsw-1 Received: by mail-qv1-f72.google.com with SMTP id u8so12225843qvm.5 for ; Mon, 08 Feb 2021 19:02:35 -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=tR/UuXaqBaROltUbV2RDYpoyLXOK1N4qjZ6UzYcMHb0=; b=TDFRFMh0yFasGchMevqH3HZtE3zq/ophpXjuGpfvA/wmM5U5CMGwKmijipxc9RLkwg FiqCW3x5xrnv8XcMD9swAbUliEGNYGRYmI08Rbb+C9jQDV0Z5T3K1tB/4GXWoOWZqqX/ 8yIwn/j4Qc7YAPoqBidv/INg49qd66SYjfrLQmvDabzS5BLxMYi/9yCLpq0F9hTsXCA1 Eh1d8B+6JeFH4BfA6EG8u5JDhkosHUJC1ktKojb4DCqPOF7+HFwWDNmrYMmXAbqQM+Ee nDStt6DxtP7IzLpz7VmMduXAxHgUWzwYMCGf+lICk7uZffyleEd1kuG54CheapD9Uyu5 g2Vg== X-Gm-Message-State: AOAM533PGB4FmDx1XY9TJu7JUVHqRvoWC2CoR39ibhkD4ay+w5MULS82 rprxxPLXlGpVMrgxWxmazJ07rxT02qjLXBFofA+EiIfUk5whS9nDVG5AC0sY9GFINOrSaK/xUGk c6ZOageUgmD41gF8DmncC/aUwa0DXer+jhtsS++qBdbrvaMKMVgYY1CX+i97d X-Received: by 2002:a0c:a905:: with SMTP id y5mr19341949qva.55.1612839754354; Mon, 08 Feb 2021 19:02:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLHspfWpI6dEM2H1FKYzO8yoaXtFXKAxy9ewDvI5IRLUI759Dc6OnoCgk4yPZj+ynYz1yRpQ== X-Received: by 2002:a0c:a905:: with SMTP id y5mr19341901qva.55.1612839753827; Mon, 08 Feb 2021 19:02:33 -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 z20sm17078830qki.93.2021.02.08.19.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 19:02:33 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Linus Torvalds , Kirill Tkhai , Mike Rapoport , David Gibson , Kirill Shutemov , Christoph Hellwig , Miaohe Lin , Gal Pressman , Jason Gunthorpe , Jann Horn , peterx@redhat.com, Jan Kara , Wei Zhang , Mike Kravetz , Andrea Arcangeli , Andrew Morton Subject: [PATCH v4 1/5] hugetlb: Dedup the code to add a new file_region Date: Mon, 8 Feb 2021 22:02:25 -0500 Message-Id: <20210209030229.84991-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210209030229.84991-1-peterx@redhat.com> References: <20210209030229.84991-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 6ef278ecf7ff..ec8e29c805fe 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;