Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2592363ybt; Mon, 22 Jun 2020 02:15:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ84kbh3fTuM/UGakiXZhckx0fmsDD4ZWp5Y4WWUOhmaVX/zx04SDTtAmUqyQvT5vswn8v X-Received: by 2002:a50:ec0f:: with SMTP id g15mr16335091edr.359.1592817317220; Mon, 22 Jun 2020 02:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592817317; cv=none; d=google.com; s=arc-20160816; b=xaWoRs4ukVdAtAI5ogf5CFV/iAAtf+g5vVluoRZQHWgl+BU8H7Zb7V6k7h2ELoSfnt prMdSdIKMVxEw16iXVzA0lsu/7wJyS7+I/WeJ8LetnFlEN4xz82IJdMO22GcOXbueljL e5LARbBBZ+9bwSWqEJR3VmbwCRXX6ehuJiVH6sP0FatNaed8VnAt9qsdUhuCe4pbTpAi FXjjwsSqbqFZBs3HlCwlH7dZUseK4rU/hyOHGpGikOyU6jq0BHxrrXeNlx+yDdmEGlqK GzNeWjakA94UpaVykBpZ5AIQfb3U6DOtqZhBElNNvLyXc+dnvx3wDeTgtbY8QRzd1sc/ Il2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=9/+aOAfZgXui7cSklavAcs2VaIRNoYeZzPEiqozaFt4=; b=EFhyhVk3Tnk0R0+lFC2kwkQ/0Ablm22Iyj1yFY6Myd2J23ljxS2uzcYh/qrTwnDLfc Vhb3U5D2lBAgr+pbWo8LAAgQbpsFSyzkIUh2bVqgWdTAFovn1Bioir82O9U9bU1c93PC 9Id0qJjgwCgUyzh+acehUPYpCRf/e8gxTAcYDYEWT2FuPivayAkGLAWHKVx5RuJsaS/E QqfO7ZdgxaqWcss532EpQdOPlPU7pZxegE7eJchMb+QZGY/ImxtJJD/VP18n7OSHLVs4 dylHZjOi1VDI1Cfl2lao9Mvp8n+YwmSFoYXCfYb8kcbIYW0ysz+JB9KmP7H2GKunECJF 7YzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jt18si8469655ejb.445.2020.06.22.02.14.54; Mon, 22 Jun 2020 02:15:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726676AbgFVJLO (ORCPT + 99 others); Mon, 22 Jun 2020 05:11:14 -0400 Received: from mail-ej1-f65.google.com ([209.85.218.65]:34943 "EHLO mail-ej1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgFVJLN (ORCPT ); Mon, 22 Jun 2020 05:11:13 -0400 Received: by mail-ej1-f65.google.com with SMTP id rk21so871929ejb.2 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=MVNn/Gp1txtUERpJF27Fjo3pA/5lC5aOW4VFGtkWvrnqJX6BH4mIyVasE2EYkV0RdU d83YyeduvVJ6EnAwvg9BKyqh6cEBrCsueFWnPtwgQPjKnC+HDglwVhErXYcv7Wh8nI0O wI6sGlP0iPJEWVxMCnDJ3cDe9jcbICzq0X2jIuYVjka0JLdrD6kG+5qOr/R+pW+pIFND YgAC+8evinuGjVR0HKYTH1lvUceJPtxsISl9vvCl43I77EYCFcr99CS0jC5xww8OJciO ChPbVqIJoHQq0AUqeFV+d+7RwPLCMEEiLPox6GoXv4XjuAP1mDbe3VB8c+yj3H3xbzWe FSgg== X-Gm-Message-State: AOAM533lENvfVXcOSUw83M4k3ROLK7hWjTy36TX8PUehF1QSaw/gtMle qNDhI5+KkG32uJQF8xJ7MRo= 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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