Skip to content

Instantly share code, notes, and snippets.

View wenjianhn's full-sized avatar
🐢

Jian Wen wenjianhn

🐢
  • Xiaomi
  • Beijing, China
  • 09:42 (UTC +08:00)
View GitHub Profile
@wenjianhn
wenjianhn / test_setsockopt.c
Created January 29, 2015 03:01
Test setsockopt with SO_PRIORITY and IP_TOS. It shows that order matters.
#include <assert.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
void test_setsockopt(int priority_first)
{
int priority = 6;
@wenjianhn
wenjianhn / slab_content_top.py
Created April 17, 2021 04:54
A simple script that helps find the root cause of a memory leak issue
#!/usr/bin/env python
from __future__ import print_function
import re
import shlex
import sys
import subprocess
from collections import Counter
@wenjianhn
wenjianhn / test_socket_prio_and_tos.c
Created January 29, 2015 03:30
Test if setsockopt(SO_PRIORITY) sets the IP type-of-service (TOS) field or not.
#include <assert.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
void test_setsockopt()
{
int priority = 6;
@wenjianhn
wenjianhn / mem_by_stack.py
Created October 25, 2021 08:33
Analyzing allocation and freeing events(includes kmem:mm_page_alloc, kmem:mm_page_alloc_zone_locked, kmem:mm_page_free, kmem:mm_page_free_batched and kmem:mm_page_pcpu_drain)
#!/usr/bin/env python
from __future__ import print_function
import sys
from collections import Counter
def get_order(head):
h = head.split()
@wenjianhn
wenjianhn / perf_record_when_high_sys.py
Created December 2, 2020 14:18
perf_record_when_high_sys
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import time
def perf_record(sys_threshold, interval, count):
while True:
@wenjianhn
wenjianhn / uaf.c
Created October 23, 2020 02:04
Bench mark the cost of doing kmalloc() then kfree()
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/slab.h>
static u64 read_tsc(void)
{
return (u64)rdtsc_ordered();
}
vncviewer -nocursorshape -quality 0 -compresslevel 9 -encodings Tight -bgr233 localhost:5902
@wenjianhn
wenjianhn / modify_dns_record.sh
Created June 17, 2013 00:44
#cloudflare modify dns record
#!/bin/bash -e
if [[ $1 == "" ]]
then
file=`basename $0`
echo "Usage:"
echo " $file IP"
# TODO(wenjianhn): subname name and more as args
# echo: example
exit 1
@wenjianhn
wenjianhn / conntrack-i-benchmark
Created April 3, 2013 14:02
"conntrack -I" benchmark
#!/bin/bash
if [[ $UID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
service conntrackd stop
# stop conntrackd.The daemon maybe writes the information about destroyed connections to a logfile.
# /var/log/conntrackd-stats.log
@wenjianhn
wenjianhn / rysnc-without-ssh
Created January 7, 2013 03:01
patch against a5dc49c1e2d3173a0d336beb260bacad7441d99a
commit 9ec031bdee4633a3386cddfca791330680834b69
Author: Jian Wen <wenjianhn@gmail.com>
Date: Fri Sep 14 17:42:21 2012 +0800
libvirt: Add copying image via rsync without ssh support
Change-Id: I4f4ec1b8466a4e8a8337f56f60473efc3b6bac00
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 41bbd2d..281d34b 100644