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=-1.0 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 98AEEC433DF for ; Mon, 22 Jun 2020 09:11:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63E4E206E2 for ; Mon, 22 Jun 2020 09:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63E4E206E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C8F786B0002; Mon, 22 Jun 2020 05:11:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1C366B0006; Mon, 22 Jun 2020 05:11:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE2456B0007; Mon, 22 Jun 2020 05:11:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 9E5046B0002 for ; Mon, 22 Jun 2020 05:11:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6A6476D67 for ; Mon, 22 Jun 2020 09:11:12 +0000 (UTC) X-FDA: 76956278784.28.lead92_3b0a18d26e31 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 459638127 for ; Mon, 22 Jun 2020 09:11:12 +0000 (UTC) X-HE-Tag: lead92_3b0a18d26e31 X-Filterd-Recvd-Size: 5553 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 09:11:11 +0000 (UTC) Received: by mail-ej1-f65.google.com with SMTP id w16so17239526ejj.5 for ; Mon, 22 Jun 2020 02:11:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9/+aOAfZgXui7cSklavAcs2VaIRNoYeZzPEiqozaFt4=; b=Yr50Zc1hl4NPllAYNu96hyOKWsitrWOW6xet23nHhfX1Z88/2+98tNpjP7sYQWXeM1 aQfBF9LVVkj7chcGqOLoPz+hj3KULJwWX4EElTkbz0kYBxbUwqRzP2gjLNDGjKapD0XK WEzUI7oCA8ffqjnXAIOe859ZC6Zo0gcPjz+JKiX7VZrMa+GxJb9+1ggq46txoCd6p/7N P1JIQE7Z/0eWRyqqoWyWqrvEOAHFdJhT3u7hRecL7BwvsTPhIEdo98z5a9eynPcDzKau Bo7YP7YjghgmZdeVBDYiGzS6QRZZ/Bd/F9EwN8lR17yn2/xWfwh945f76e4eZgqscbuY FxkA== X-Gm-Message-State: AOAM532HZggIQfqke3WcXUewkNWJhKwQIXMr3MmexQxWaCkwh2kLsX/J kaTypmbK8fl2UCTxGTGWJ4E= X-Google-Smtp-Source: ABdhPJyX3qvBAqhH7CUaP2WbSDBYBZjOngkM2TgbzwevZSibP9vNVRV5TQimWNm/ZNotvqD4cdIU6g== X-Received: by 2002:a17:906:1394:: with SMTP id f20mr6249593ejc.114.1592817070665; Mon, 22 Jun 2020 02:11:10 -0700 (PDT) Received: from localhost (ip-37-188-173-135.eurotel.cz. [37.188.173.135]) by smtp.gmail.com with ESMTPSA id f17sm12280462edj.32.2020.06.22.02.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:11:09 -0700 (PDT) Date: Mon, 22 Jun 2020 11:11:07 +0200 From: Michal Hocko To: Jaewon Kim Cc: vbabka@suse.cz, bhe@redhat.com, mgorman@techsingularity.net, minchan@kernel.org, mgorman@suse.de, hannes@cmpxchg.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, ytk.lee@samsung.com, cmlaika.kim@samsung.com Subject: Re: [PATCH v4] page_alloc: consider highatomic reserve in watermark fast Message-ID: <20200622091107.GC31426@dhcp22.suse.cz> References: <20200619235958.11283-1-jaewon31.kim@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200619235958.11283-1-jaewon31.kim@samsung.com> X-Rspamd-Queue-Id: 459638127 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: On Sat 20-06-20 08:59:58, Jaewon Kim wrote: [...] > @@ -3502,19 +3525,12 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, > const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); > > /* free_pages may go negative - that's OK */ > - free_pages -= (1 << order) - 1; > + free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); > > if (alloc_flags & ALLOC_HIGH) > min -= min / 2; > > - /* > - * If the caller does not have rights to ALLOC_HARDER then subtract > - * the high-atomic reserves. This will over-estimate the size of the > - * atomic reserve but it avoids a search. > - */ > - if (likely(!alloc_harder)) { > - free_pages -= z->nr_reserved_highatomic; > - } else { > + if (unlikely(alloc_harder)) { > /* > * OOM victims can try even harder than normal ALLOC_HARDER > * users on the grounds that it's definitely going to be in [...] > @@ -3582,25 +3591,22 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order, > unsigned long mark, int highest_zoneidx, > unsigned int alloc_flags) > { > - long free_pages = zone_page_state(z, NR_FREE_PAGES); > - long cma_pages = 0; > + long free_pages; > + long unusable_free; > > -#ifdef CONFIG_CMA > - /* If allocation can't use CMA areas don't use free CMA pages */ > - if (!(alloc_flags & ALLOC_CMA)) > - cma_pages = zone_page_state(z, NR_FREE_CMA_PAGES); > -#endif > + free_pages = zone_page_state(z, NR_FREE_PAGES); > + unusable_free = __zone_watermark_unusable_free(z, order, alloc_flags); > > /* > * Fast check for order-0 only. If this fails then the reserves > - * need to be calculated. There is a corner case where the check > - * passes but only the high-order atomic reserve are free. If > - * the caller is !atomic then it'll uselessly search the free > - * list. That corner case is then slower but it is harmless. > + * need to be calculated. > */ > - if (!order && (free_pages - cma_pages) > > - mark + z->lowmem_reserve[highest_zoneidx]) > - return true; > + if (!order) { > + long fast_free = free_pages - unusable_free; > + > + if (fast_free > mark + z->lowmem_reserve[highest_zoneidx]) > + return true; > + } There is no user of unusable_free for order > 0. With you current code __zone_watermark_unusable_free would be called twice for high order allocations unless compiler tries to be clever.. But more importantly, I have hard time to follow why we need both zone_watermark_fast and zone_watermark_ok now. They should be essentially the same for anything but order == 0. For order 0 the only difference between the two is that zone_watermark_ok checks for ALLOC_HIGH resp ALLOC_HARDER, ALLOC_OOM. So what is exactly fast about the former and why do we need it these days? > > return __zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, > free_pages); > -- > 2.17.1 > -- Michal Hocko SUSE Labs