Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mds: automate MDS object count tracking #13591

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/include/counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2017 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/

#ifndef CEPH_COUNTER_H
#define CEPH_COUNTER_H

template <typename T>
class Counter {
public:
Counter() {
_count()++;
_increments()++;
}
Counter(const Counter &rhs) {
_count()++;
_increments()++;
}
Counter(Counter &&rhs) {}
~Counter() {
_count()--;
}
static unsigned long count() {
return _count();
}
static unsigned long increments() {
return _increments();
}
static unsigned long decrements() {
return increments()-count();
}

private:
static unsigned long &_count() {
static unsigned long c;
return c;
}
static unsigned long &_increments() {
static unsigned long i;
return i;
}
};

#endif
12 changes: 2 additions & 10 deletions src/mds/CDentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <set>

#include "include/counter.h"
#include "include/types.h"
#include "include/buffer_fwd.h"
#include "include/lru.h"
Expand All @@ -46,7 +47,7 @@ class Session;
bool operator<(const CDentry& l, const CDentry& r);

// dentry
class CDentry : public MDSCacheObject, public LRUObject {
class CDentry : public MDSCacheObject, public LRUObject, public Counter<CDentry> {
public:
friend class CDir;

Expand Down Expand Up @@ -106,8 +107,6 @@ class CDentry : public MDSCacheObject, public LRUObject {
versionlock(this, &versionlock_type),
dir(0),
version(0), projected_version(0) {
g_num_dn++;
g_num_dna++;
}
CDentry(const std::string& n, __u32 h, inodeno_t ino, unsigned char dt,
snapid_t f, snapid_t l) :
Expand All @@ -118,16 +117,9 @@ class CDentry : public MDSCacheObject, public LRUObject {
versionlock(this, &versionlock_type),
dir(0),
version(0), projected_version(0) {
g_num_dn++;
g_num_dna++;
linkage.remote_ino = ino;
linkage.remote_d_type = dt;
}
~CDentry() {
g_num_dn--;
g_num_dns++;
}


static void *operator new(size_t num_bytes) {
void *n = pool.malloc();
Expand Down
3 changes: 0 additions & 3 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) :
num_dentries_auth_subtree_nested(0),
dir_auth(CDIR_AUTH_DEFAULT)
{
g_num_dir++;
g_num_dira++;

state = STATE_INITIAL;

memset(&fnode, 0, sizeof(fnode));
Expand Down
7 changes: 2 additions & 5 deletions src/mds/CDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef CEPH_CDIR_H
#define CEPH_CDIR_H

#include "include/counter.h"
#include "include/types.h"
#include "include/buffer_fwd.h"
#include "common/bloom_filter.hpp"
Expand All @@ -41,7 +42,7 @@ class MDCache;
struct ObjectOperation;

ostream& operator<<(ostream& out, const class CDir& dir);
class CDir : public MDSCacheObject {
class CDir : public MDSCacheObject, public Counter<CDir> {
friend ostream& operator<<(ostream& out, const class CDir& dir);

/*
Expand Down Expand Up @@ -404,10 +405,6 @@ class CDir : public MDSCacheObject {

public:
CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth);
~CDir() {
g_num_dir--;
g_num_dirs++;
}

const scrub_info_t *scrub_info() const {
if (!scrub_infop) {
Expand Down
7 changes: 2 additions & 5 deletions src/mds/CInode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define CEPH_CINODE_H

#include "common/config.h"
#include "include/counter.h"
#include "include/elist.h"
#include "include/types.h"
#include "include/lru.h"
Expand Down Expand Up @@ -127,7 +128,7 @@ class InodeStore : public InodeStoreBase {
WRITE_CLASS_ENCODER_FEATURES(InodeStore)

// cached inode wrapper
class CInode : public MDSCacheObject, public InodeStoreBase {
class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CInode> {
/*
* This class uses a boost::pool to handle allocation. This is *not*
* thread-safe, so don't do allocations from multiple threads!
Expand Down Expand Up @@ -681,14 +682,10 @@ class CInode : public MDSCacheObject, public InodeStoreBase {
policylock(this, &policylock_type),
loner_cap(-1), want_loner_cap(-1)
{
g_num_ino++;
g_num_inoa++;
state = 0;
if (auth) state_set(STATE_AUTH);
}
~CInode() {
g_num_ino--;
g_num_inos++;
close_dirfrags();
close_snaprealm();
clear_file_locks();
Expand Down
9 changes: 2 additions & 7 deletions src/mds/Capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef CEPH_CAPABILITY_H
#define CEPH_CAPABILITY_H

#include "include/counter.h"
#include "include/buffer_fwd.h"
#include "include/xlist.h"

Expand Down Expand Up @@ -63,7 +64,7 @@ namespace ceph {
class Formatter;
}

class Capability {
class Capability : public Counter<Capability> {
public:
struct Export {
int64_t cap_id;
Expand Down Expand Up @@ -123,14 +124,8 @@ class Capability {
last_issue(0),
mseq(0),
suppress(0), state(0) {
g_num_cap++;
g_num_capa++;
}
Capability(const Capability& other); // no copying
~Capability() {
g_num_cap--;
g_num_caps++;
}


static void *operator new(size_t num_bytes) {
Expand Down
15 changes: 0 additions & 15 deletions src/mds/MDCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,6 @@ static ostream& _prefix(std::ostream *_dout, MDSRank *mds) {
return *_dout << "mds." << mds->get_nodeid() << ".cache ";
}

long g_num_ino = 0;
long g_num_dir = 0;
long g_num_dn = 0;
long g_num_cap = 0;

long g_num_inoa = 0;
long g_num_dira = 0;
long g_num_dna = 0;
long g_num_capa = 0;

long g_num_inos = 0;
long g_num_dirs = 0;
long g_num_dns = 0;
long g_num_caps = 0;

set<int> SimpleLock::empty_gather_set;


Expand Down
26 changes: 13 additions & 13 deletions src/mds/MDSRank.cc
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,19 @@ bool MDSRank::_dispatch(Message *m, bool new_msg)
*/

if (mlogger) {
mlogger->set(l_mdm_ino, g_num_ino);
mlogger->set(l_mdm_dir, g_num_dir);
mlogger->set(l_mdm_dn, g_num_dn);
mlogger->set(l_mdm_cap, g_num_cap);

mlogger->inc(l_mdm_inoa, g_num_inoa); g_num_inoa = 0;
mlogger->inc(l_mdm_inos, g_num_inos); g_num_inos = 0;
mlogger->inc(l_mdm_dira, g_num_dira); g_num_dira = 0;
mlogger->inc(l_mdm_dirs, g_num_dirs); g_num_dirs = 0;
mlogger->inc(l_mdm_dna, g_num_dna); g_num_dna = 0;
mlogger->inc(l_mdm_dns, g_num_dns); g_num_dns = 0;
mlogger->inc(l_mdm_capa, g_num_capa); g_num_capa = 0;
mlogger->inc(l_mdm_caps, g_num_caps); g_num_caps = 0;
mlogger->set(l_mdm_ino, CInode::count());
mlogger->set(l_mdm_dir, CDir::count());
mlogger->set(l_mdm_dn, CDentry::count());
mlogger->set(l_mdm_cap, Capability::count());

mlogger->set(l_mdm_inoa, CInode::increments());
mlogger->set(l_mdm_inos, CInode::decrements());
mlogger->set(l_mdm_dira, CDir::increments());
mlogger->set(l_mdm_dirs, CDir::decrements());
mlogger->set(l_mdm_dna, CDentry::increments());
mlogger->set(l_mdm_dns, CDentry::decrements());
mlogger->set(l_mdm_capa, Capability::increments());
mlogger->set(l_mdm_caps, Capability::decrements());

mlogger->set(l_mdm_buf, buffer::get_total_alloc());
}
Expand Down
5 changes: 0 additions & 5 deletions src/mds/mdstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ class mds_role_t
std::ostream& operator<<(std::ostream &out, const mds_role_t &role);


extern long g_num_ino, g_num_dir, g_num_dn, g_num_cap;
extern long g_num_inoa, g_num_dira, g_num_dna, g_num_capa;
extern long g_num_inos, g_num_dirs, g_num_dns, g_num_caps;


// CAPS

inline string gcap_string(int cap)
Expand Down