From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 43B63CA9ED4 for ; Mon, 4 Nov 2019 21:19:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EDB3F20869 for ; Mon, 4 Nov 2019 21:19:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="D9p5Nchb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDB3F20869 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9D0566B0003; Mon, 4 Nov 2019 16:19:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9808B6B0005; Mon, 4 Nov 2019 16:19:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 848056B0006; Mon, 4 Nov 2019 16:19:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 6F8BF6B0003 for ; Mon, 4 Nov 2019 16:19:31 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 11FA6824999B for ; Mon, 4 Nov 2019 21:19:31 +0000 (UTC) X-FDA: 76119861342.19.waste17_35eea4d3ac11b X-HE-Tag: waste17_35eea4d3ac11b X-Filterd-Recvd-Size: 8436 Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Nov 2019 21:19:30 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id n48so15703033ota.11 for ; Mon, 04 Nov 2019 13:19:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/8yU3O5k24h9e3PyFN4Dj6MFbBb6JVOj0JoMWY+S3AE=; b=D9p5NchbwDhe9mp8NmRpUK2kC/a+iNk7mb4uEiZ8i732RHQD6+tLGJUqQxUtZVO/6E cj1d8a4CJKXF8pG7Zq7JEeo0VUK3rLYbIqPfzCn9VAy0MLJ3rg/OY1kog7CQmyv2Amrc JcgPRVvZUwSxwpa+ttmnJcoylJD3NkiLLnmjKjCHY/C1g4stQ8Ed1DyQrK1adfzuqzG0 UtqL7KFhK1ty8dRL3C+GxB04afBz9u4VTY09zYZBWWaqrssMfw3imLZpgVrl9CnzcqC5 01mxKNlxFe9J0MLshePp0EkD4m82n/DCA8btqZnttBF+d3W3jxDnTftdC5+8WtGvIWYe 1bqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/8yU3O5k24h9e3PyFN4Dj6MFbBb6JVOj0JoMWY+S3AE=; b=SmkndBgS4azyplnQP9FCQ12uJVioWuxXVaIx87DOTds0IjxRN4OWFFuZ5SklIrVeVQ 4Jq5efJo0U907pX7wqG3byuqtOhKCwokpKuAOWXMb5Jf7on0HPYP9MYcOXoRVSVkjllQ vLDy5hrt6Tw/ff0P2P1Lak0IVo0VY/jPntJ/nAaWVlXWcKX65M15vaQYvo3kingcvNa7 bzw7AdznXfjeyWGzLSVyzET4rAi+DJ9ufTFF5OSS6j2pqdFpkR/1T3UzDm2uDA/QR3mt OmXnXRtkK+vuA2AKhAH7KCEFQN4q0NYBW7DltiBPA1eFMMkSeOoI4NgKpTBgbviy9lIm DCaA== X-Gm-Message-State: APjAAAXKmYZgFosSAHP0VRuJ9Fub1IOWpplV3bmeQwLx3TMMEIDPPJ+i 8nj/QUSNJcQB9+IASvkBuhmPi2fNd/ffL7u8okKgYA== X-Google-Smtp-Source: APXvYqwoI3V0DEHS32l9wQXVJE8EeGtjkg4VAjYe1lFrEIq00wE4DXN1gIePuof1MESKaL2zUS9xhTdMaCNp6fuM05o= X-Received: by 2002:a9d:1c8f:: with SMTP id l15mr16022901ota.313.1572902369377; Mon, 04 Nov 2019 13:19:29 -0800 (PST) MIME-Version: 1.0 References: <20191030013701.39647-1-almasrymina@google.com> <20191030013701.39647-5-almasrymina@google.com> <1c060bde-8d44-146c-6d67-a7b145aa1b59@oracle.com> In-Reply-To: From: Mina Almasry Date: Mon, 4 Nov 2019 13:19:18 -0800 Message-ID: Subject: Re: [PATCH v8 5/9] hugetlb: disable region_add file_region coalescing To: Mike Kravetz Cc: shuah , open list , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, cgroups@vger.kernel.org, Aneesh Kumar Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 4, 2019 at 1:15 PM Mike Kravetz wrote: > > On 11/4/19 1:04 PM, Mina Almasry wrote: > > On Fri, Nov 1, 2019 at 4:23 PM Mike Kravetz wrote: > >> > >> On 10/29/19 6:36 PM, Mina Almasry wrote: > >>> static long add_reservation_in_range(struct resv_map *resv, long f, long t, > >>> - bool count_only) > >>> + long *regions_needed, bool count_only) > >>> { > >>> - long chg = 0; > >>> + long add = 0; > >>> struct list_head *head = &resv->regions; > >>> + long last_accounted_offset = f; > >>> struct file_region *rg = NULL, *trg = NULL, *nrg = NULL; > >>> > >>> - /* Locate the region we are before or in. */ > >>> - list_for_each_entry (rg, head, link) > >>> - if (f <= rg->to) > >>> - break; > >>> + if (regions_needed) > >>> + *regions_needed = 0; > >>> > >>> - /* Round our left edge to the current segment if it encloses us. */ > >>> - if (f > rg->from) > >>> - f = rg->from; > >>> - > >>> - chg = t - f; > >>> + /* In this loop, we essentially handle an entry for the range > >>> + * [last_accounted_offset, rg->from), at every iteration, with some > >>> + * bounds checking. > >>> + */ > >>> + list_for_each_entry_safe(rg, trg, head, link) { > >>> + /* Skip irrelevant regions that start before our range. */ > >>> + if (rg->from < f) { > >>> + /* If this region ends after the last accounted offset, > >>> + * then we need to update last_accounted_offset. > >>> + */ > >>> + if (rg->to > last_accounted_offset) > >>> + last_accounted_offset = rg->to; > >>> + continue; > >>> + } > >>> > >>> - /* Check for and consume any regions we now overlap with. */ > >>> - nrg = rg; > >>> - list_for_each_entry_safe (rg, trg, rg->link.prev, link) { > >>> - if (&rg->link == head) > >>> - break; > >>> + /* When we find a region that starts beyond our range, we've > >>> + * finished. > >>> + */ > >>> if (rg->from > t) > >>> break; > >>> > >>> - /* We overlap with this area, if it extends further than > >>> - * us then we must extend ourselves. Account for its > >>> - * existing reservation. > >>> + /* Add an entry for last_accounted_offset -> rg->from, and > >>> + * update last_accounted_offset. > >>> */ > >>> - if (rg->to > t) { > >>> - chg += rg->to - t; > >>> - t = rg->to; > >>> + if (rg->from > last_accounted_offset) { > >>> + add += rg->from - last_accounted_offset; > >>> + if (!count_only) { > >>> + nrg = get_file_region_entry_from_cache( > >>> + resv, last_accounted_offset, rg->from); > >>> + list_add(&nrg->link, rg->link.prev); > >>> + } else if (regions_needed) > >>> + *regions_needed += 1; > >>> } > >>> - chg -= rg->to - rg->from; > >>> > >>> - if (!count_only && rg != nrg) { > >>> - list_del(&rg->link); > >>> - kfree(rg); > >>> - } > >>> + last_accounted_offset = rg->to; > >> > >> That last assignment is unneeded. Correct? > >> > > > > Not to make you nervous, but this assignment is needed. > > > > The basic idea is that there are 2 loop invariants here: > > 1. Everything before last_accounted_offset is filled in with file_regions. > > 2. rg points to the first region past last_account_offset. > > > > Each loop iteration compares rg->from to last_accounted_offset, and if > > there is a gap, it creates a new region to fill this gap. Then this > > assignment restores loop invariant #2 by assigning > > last_accounted_offset to rg->to, since now everything before rg->to is > > filled in with file_regions. > > > > My apologies! > > >>> } > >>> > >>> - if (!count_only) { > >>> - nrg->from = f; > >>> - nrg->to = t; > >>> + /* Handle the case where our range extends beyond > >>> + * last_accounted_offset. > >>> + */ > >>> + if (last_accounted_offset < t) { > >>> + add += t - last_accounted_offset; > >>> + if (!count_only) { > >>> + nrg = get_file_region_entry_from_cache( > >>> + resv, last_accounted_offset, t); > >>> + list_add(&nrg->link, rg->link.prev); > >>> + } else if (regions_needed) > >>> + *regions_needed += 1; > >>> + last_accounted_offset = t; > > The question about an unnecessary assignment was supposed to be > directed at the above line. > Oh, yes. That assignment is completely unnecessary; the function just exits after pretty much. Will remove, thanks! > -- > Mike Kravetz > > > >>> } > >>> > >>> - return chg; > >>> + return add; > >>> }