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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49400C19F2D for ; Tue, 9 Aug 2022 13:33:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74F7B6B0072; Tue, 9 Aug 2022 09:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FDA88E0001; Tue, 9 Aug 2022 09:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5ED8F6B0074; Tue, 9 Aug 2022 09:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4E8746B0072 for ; Tue, 9 Aug 2022 09:33:24 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1E528AAA0B for ; Tue, 9 Aug 2022 13:33:24 +0000 (UTC) X-FDA: 79780145928.29.7EBD74B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 275B2100176 for ; Tue, 9 Aug 2022 13:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Nt29pWAyIoYYn65mIhjhIKSl4BVL+y3jhFR1hUvUa2Y=; b=gt651B3yXlJR9xDJENunGu+z7E Bg1qkpbYMDKsEB0uhLdunPvwS6qNFqBvDJX52s7prEnZfkb12ScWfbEbUc8uM6gob9rYj0Qa/jIQX rTVHG0Fk7Qh6v7js+pSNfJhOSW8DskL5iBZjKPvN8gIzYVBeRiVmIVE9exiRU2fVBgl6NPHD1LBSR waHpAuUMNLFVt4rU7IigfVX8Us5v5S28IywcPTZvt9oEdIb0QYhjarUQN6QJ3jhklVR1KEBsOMvJ5 Xw/w3RRJ0wCT7Lk995nES5h48qbT45ivUXF+xfzn6yJuH1FH51Al+ap8TfQ5TT4uheZyRMh/7bE8G q8C+Kk2A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oLPMB-00FOLk-DD; Tue, 09 Aug 2022 13:33:15 +0000 Date: Tue, 9 Aug 2022 14:33:15 +0100 From: Matthew Wilcox To: alexlzhu@fb.com Cc: linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: Re: [PATCH v2] mm: add thp_utilization metrics to debugfs Message-ID: References: <20220809014950.3616464-1-alexlzhu@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220809014950.3616464-1-alexlzhu@fb.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660052003; a=rsa-sha256; cv=none; b=Eh0VJ5XT02IXxpZbGePBdTJ+dhbg4yBDkk1UcQMH/yqRE+U150prfER7JMa24hbP0SYs9A mRTKV93cAU0pqHn+9naD7JxuQErxvDbMoOYCajUhcIFYBsp/JeHqKH3VyyoLnz19eFIaXU tqbQmnaPlKUfxuYztNz1/R4Dll0PyC8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gt651B3y; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660052003; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Nt29pWAyIoYYn65mIhjhIKSl4BVL+y3jhFR1hUvUa2Y=; b=dIss7QIsvFMbN4zIdfs/NJl+0uGdPIDppL07kpanJWltT+mHgDnuck++6Lyq4K6PgJiD9Y JvCHXJGhmyRdwcgbSDUSIkwQahl52i+vm/JOqhW+r59ataNlD2EdVijwZd4B7/fGcAL4Bs tfVxd8F9RIL0pwCPbIIDYanSpxr7M1U= X-Rspamd-Queue-Id: 275B2100176 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gt651B3y; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: jk8eb38orjorpa8ijha4qmmd199xjzsn X-HE-Tag: 1660052002-935679 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 Mon, Aug 08, 2022 at 06:49:50PM -0700, alexlzhu@fb.com wrote: > +int thp_number_utilized_pages(struct page *page) > +{ > + unsigned long page_index, page_offset, value; > + int thp_nr_utilized_pages = HPAGE_PMD_NR; > + int step_size = sizeof(unsigned long); > + bool is_all_zeroes; > + void *kaddr; > + > + if (!page || !is_anon_transparent_hugepage(page)) > + return -1; > + > + kaddr = kmap_local_page(compound_head(page)); > + for (page_index = 0; page_index < HPAGE_PMD_NR; page_index++) { > + is_all_zeroes = true; > + for (page_offset = 0; page_offset < PAGE_SIZE; page_offset += step_size) { > + value = *(unsigned long *)(kaddr + page_index * PAGE_SIZE + page_offset); > + if (value != 0) { > + is_all_zeroes = false; > + break; > + } > + } > + if (is_all_zeroes) > + thp_nr_utilized_pages--; > + } > + kunmap_local(kaddr); You haven't tested this on 32-bit maachines with HIGHMEM, have you? kmap_local_page() only maps PAGE_SIZE bytes, so you need to map it and unmap each page. Also, why are you calling compound_head()? Surely you're already assuming that page is a head page here? (this is why I introduced the struct folio type, so you know whether a pointer is already to a head page and you don't need to call compound_head() again).