Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp824005ybh; Tue, 10 Mar 2020 08:55:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsDRIaKyjqmOKzcbsycb4K0p1oIxxmPl8HNlyEmbFtH7YWXqss2yXNTJIPLokSWy/Y1G/LT X-Received: by 2002:a54:468b:: with SMTP id k11mr1616990oic.134.1583855749854; Tue, 10 Mar 2020 08:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583855749; cv=none; d=google.com; s=arc-20160816; b=fLdm7UXa43Et5ZyrD9KGbXeU392gNwlEHjA3NWlh5annlq3EwgGXSQaNJ0BxKaCKd5 OeR7pHTvIj0L0mGBSxKNnnBr2G23tJdPpVZmX/aqfDw+zm77+8rpjUzQ3iMXEcoERJkp olmhDxoDYLbzlRq5QfNFS0wd3fpBkPea0rzEFxp4NaGjlbm1qFmL3sYVdIci/rEGcMiz O3csMEvUBeT8reqNVNhbqhcIqZ21+rNVmc/YGkgby0xiUG0bDtvwluntSq9oqMLtQhLu /hFofb+UHxIpx5E8oBsSAyYiKWD1KUutEpDF7q2/AUtGqzw/IKkVJJndezxTkJSdw42k +UyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=s3RG3RyLM9lmojHTrZUfAL0hvk6ag64Gl5Bi53yh8VU=; b=mE++UA9fsxMY8orZW4yGgF6qvEETwjx92nEQreBAESiquTWSP4MZrl3iCN31PeyvCf GTxRYoFsMWbhfFcgWNJg2YUe6ullfXeyowohprflqeiJ4EO5ezVFHacqavRs+2VCj2e0 3Ap3rWq6D6dPq+HY4y9IoBKe6KroqN7/oJxrTBKywsKDlkIPJuKxcppm3HecIdDbPrdq kk/mEvyLuDJABcifWhx+zXIlJW2OMWBfvs4MsltqX+YkHFw7QRQbsR5QYA03qLSYSLdY leJZ0el/Tbi11GLgT51xuI6mjzR45rNUP8TWxtYuMM9bBvrFNkuEzCU+IClpiIr+7L2O 4icA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si5395586oij.113.2020.03.10.08.55.38; Tue, 10 Mar 2020 08:55:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgCJPzS (ORCPT + 99 others); Tue, 10 Mar 2020 11:55:18 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2542 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726480AbgCJPzR (ORCPT ); Tue, 10 Mar 2020 11:55:17 -0400 Received: from lhreml706-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 8A3E3C6E21A78A430E07; Tue, 10 Mar 2020 15:55:13 +0000 (GMT) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml706-cah.china.huawei.com (10.201.108.47) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 10 Mar 2020 15:55:13 +0000 Received: from localhost (10.202.226.57) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 10 Mar 2020 15:55:12 +0000 Date: Tue, 10 Mar 2020 15:55:10 +0000 From: Jonathan Cameron To: SeongJae Park CC: , SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v6 02/14] mm/damon: Implement region based sampling Message-ID: <20200310155510.000025d2@Huawei.com> In-Reply-To: <20200310115233.23246-1-sjpark@amazon.com> References: <20200310085721.00000a0f@Huawei.com> <20200310115233.23246-1-sjpark@amazon.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.57] X-ClientProxiedBy: lhreml715-chm.china.huawei.com (10.201.108.66) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 Mar 2020 12:52:33 +0100 SeongJae Park wrote: > Added replies to your every comment in line below. I agree to your whole > opinions, will apply those in next spin! :) > One additional question inline that came to mind. Using a single statistic to monitor huge page and normal page hits is going to give us problems I think. Perhaps I'm missing something? > > > +/* > > > + * Check whether the given region has accessed since the last check > > > > Should also make clear that this sets us up for the next access check at > > a different memory address it the region. > > > > Given the lack of connection between activities perhaps just split this into > > two functions that are always called next to each other. > > Will make the description more clearer as suggested. > > Also, I found that I'm not clearing *pte and *pmd before going 'mkold', thanks > to this comment. Will fix it, either. > > > > > > + * > > > + * mm 'mm_struct' for the given virtual address space > > > + * r the region to be checked > > > + */ > > > +static void kdamond_check_access(struct damon_ctx *ctx, > > > + struct mm_struct *mm, struct damon_region *r) > > > +{ > > > + pte_t *pte = NULL; > > > + pmd_t *pmd = NULL; > > > + spinlock_t *ptl; > > > + > > > + if (follow_pte_pmd(mm, r->sampling_addr, NULL, &pte, &pmd, &ptl)) > > > + goto mkold; > > > + > > > + /* Read the page table access bit of the page */ > > > + if (pte && pte_young(*pte)) > > > + r->nr_accesses++; > > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > > > Is it worth having this protection? Seems likely to have only a very small > > influence on performance and makes it a little harder to reason about the code. > > It was necessary for addressing 'implicit declaration' problem of 'pmd_young()' > and 'pmd_mkold()' for build of DAMON on several architectures including User > Mode Linux. > > Will modularize the code for better readability. > > > > > > + else if (pmd && pmd_young(*pmd)) > > > + r->nr_accesses++; So we increment a region count by one if we have an access in a huge page, or in a normal page. If we get a region that has a mixture of the two, this seems likely to give a bad approximation. Assume the region is accessed 'evenly' but each " 4k page" is only hit 10% of the time (where a hit is in one check period) If our address in a page, then we'll hit 10% of the time, but if it is in a 2M huge page then we'll hit a much higher percentage of the time. 1 - (0.9^512) ~= 1 Should we look to somehow account for this? > > > +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > > + > > > + spin_unlock(ptl); > > > + > > > +mkold: > > > + /* mkold next target */ > > > + r->sampling_addr = damon_rand(ctx, r->vm_start, r->vm_end); > > > + > > > + if (follow_pte_pmd(mm, r->sampling_addr, NULL, &pte, &pmd, &ptl)) > > > + return; > > > + > > > + if (pte) { > > > + if (pte_young(*pte)) { > > > + clear_page_idle(pte_page(*pte)); > > > + set_page_young(pte_page(*pte)); > > > + } > > > + *pte = pte_mkold(*pte); > > > + } > > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > > + else if (pmd) { > > > + if (pmd_young(*pmd)) { > > > + clear_page_idle(pmd_page(*pmd)); > > > + set_page_young(pmd_page(*pmd)); > > > + } > > > + *pmd = pmd_mkold(*pmd); > > > + } > > > +#endif > > > + > > > + spin_unlock(ptl); > > > +} > > > +