Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp694351pxk; Sun, 30 Aug 2020 20:15:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKgsRCe9C34K/mWOu+L0VG1KFDx+EperRt/Ub7fZv6lJ6/xpUGxcLRyL7+8evCWDyHLvwn X-Received: by 2002:a17:906:b2c7:: with SMTP id cf7mr4564286ejb.185.1598843718114; Sun, 30 Aug 2020 20:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598843718; cv=none; d=google.com; s=arc-20160816; b=akmqLlZ+AzBg3wKRgQvIUrcwTKssOSzaqw2wGGNSLUVgaCklsGofBV1X4+sqmSKRO6 2aXlNC/q90QKD4CPiXWDMklNG6DX6cNDS1rePsxzhyTJGWEs5vpwBAhm+Q2+N7UCfAS8 8L1vxqP6TuJVh0mtUQWAHgmfe/GJRAn3w84ARJG5YilwONQnb+cI2l5ErdfLeu0r1X1r Dij0p1w+/7PVAyVqAk4GVy0dtb56SlKiDixNB43yx9ed0wzZmKjG6V3NKgn2hEuOVxW8 elMV34yfyj3kZI62koganQu79YdzThkf/sh33OU/4hqU/jBl2hKqV0eGwEULaWzDtPmp 4DWw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zKn8ML58sxstXxQEeY34JYGcT7oHcJvV6sqrOXgBPj0=; b=kMzxxAfj3G1aMsCm6KxHa0EreF5ahUoqghLBaTxF7kj/495cPexUkwXts+nbx0G9v/ 3I8Rkc5H9P0vHH79se/nBpueYYAueSHZ/+6rmpIDvwIYz38q3w+/OGzin7QgIF9rmJhf aDJMl1xOX392OjAHBacsK0e7RrUwiHYCMFtCZgtQTG1ze2MtfJdvUqZHjF89YOtikWL4 ILtQquPX5v7cjsrqSyY/egODHK7IDtLQ/2eYZgEXglNYfApeRSxIYa8qColtdmROuIqP /KQM+1XZi2Ena9KjSeURULRWl/FDOzpeinBEBf8km6p1m1M2fvfI9kwVqsiGEoiQFDqm Oj+w== 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si3082654edm.413.2020.08.30.20.14.55; Sun, 30 Aug 2020 20:15:18 -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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbgHaDLN (ORCPT + 99 others); Sun, 30 Aug 2020 23:11:13 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:41464 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726573AbgHaDLM (ORCPT ); Sun, 30 Aug 2020 23:11:12 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07425;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0U7JHBzW_1598843468; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U7JHBzW_1598843468) by smtp.aliyun-inc.com(127.0.0.1); Mon, 31 Aug 2020 11:11:08 +0800 From: Wei Yang To: rostedt@goodmis.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 4/6] ftrace: simplify the calculation of page number for ftrace_page->records Date: Mon, 31 Aug 2020 11:11:02 +0800 Message-Id: <20200831031104.23322-5-richard.weiyang@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20200831031104.23322-1-richard.weiyang@linux.alibaba.com> References: <20200831031104.23322-1-richard.weiyang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the following two reasones, we could simplify the calculation: - If the number after roundup count is not power of 2, we would definitely have more than 1 empty page with a higher order. - get_count_order() just return current order, so one lower order could meet the requirement. The calculation could be simplified by lower one order level when pages are not power of 2. Signed-off-by: Wei Yang --- kernel/trace/ftrace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 9021e16fa079..15fcfa16895d 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3127,18 +3127,19 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs) static int ftrace_allocate_records(struct ftrace_page *pg, int count) { int order; - int cnt; + int pages, cnt; if (WARN_ON(!count)) return -EINVAL; - order = get_count_order(DIV_ROUND_UP(count, ENTRIES_PER_PAGE)); + pages = DIV_ROUND_UP(count, ENTRIES_PER_PAGE); + order = get_count_order(pages); /* * We want to fill as much as possible. No more than a page * may be empty. */ - while ((PAGE_SIZE << order) / ENTRY_SIZE >= count + ENTRIES_PER_PAGE) + if (!is_power_of_2(pages)) order--; again: -- 2.20.1 (Apple Git-117)