'CS/Linux'에 해당되는 글 8건

  1. 2014.10.02 Devstack (Icehouse) 설치 (Neutron)
  2. 2014.03.26 SSH login without password
  3. 2012.11.01 Linux IO Stack Diagram
  4. 2012.11.01 이미지 파일 생성 / 마운트
  5. 2011.09.08 Ubuntu에서 고정 IP 설정
  6. 2011.09.08 SSH login without password
  7. 2011.05.20 Why not mmap?
  8. 2011.03.14 [LINUX] execl

Devstack (Icehouse) 설치 (Neutron)

CS/Linux 2014.10.02 06:17

TODO : Network topology

TODO : Multi-Node

TODO : Host network settings



/etc/network/interfaces

# Public / Management network

auto eth0
iface eth0 inet static
      address 192.168.55.11
      netmask 255.255.255.0
      gateway 192.168.55.1
      dns-nameservers 8.8.8.8


# Data network
auto eth1
iface eth1 inet manual
      up ip link set $IFACE up
      down ip link set $IFACE down



# ovs-vsctl add-port br-int eth1

# ovs-vsctl add-port br-eth1 eth1



# groupadd stack
# useradd -g stack -s /bin/bash -d /opt/stack -m stack

# echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers


# git clone -b stable/icehouse devstack https://github.com/openstack-dev/devstack.git



local.conf

[[local|localrc]]

HOST_IP=192.168.55.11
MULTI_HOST=True

FLAT_INTERFACE=eth1

PHYSICAL_NETWORK=physnet1
OVS_PHYSICAL_BRIDGE=br-eth1

FLOATING_RANGE=172.16.0.0/16
PUBLIC_NETWORK_GATEWAY=172.16.0.1
Q_FLOATING_ALLOCATION_POOL=start=172.16.0.2,end=172.16.254.254

FIXED_RANGE=10.0.0.0/16
NETWORK_GATEWAY=10.0.0.1


disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service neutron

LOGFILE=/opt/stack/logs/stack.sh.log

ADMIN_PASSWORD=stack
MYSQL_PASSWORD=stack
RABBIT_PASSWORD=stack
SERVICE_PASSWORD=stack
SERVICE_TOKEN=stacktoken

GLANCE_BRANCH=stable/icehouse
HORIZON_BRANCH=stable/icehouse
KEYSTONE_BRANCH=stable/icehouse
NOVA_BRANCH=stable/icehouse
NEUTRON_BRANCH=stable/icehouse
HEAT_BRANCH=stable/icehouse
CEILOMETER_BRANCH=stable/icehouse


IMAGE_URLS+=",http://fedorapeople.org/groups/heat/prebuilt-jeos-images/F17-x86_64-cfntools.qcow2"



$ cd /path/to/devstack

$ ./stack.sh



# iptables -t nat -A POSTROUTING -s 172.16.0.0/16 -o eth0 -j MASQUERADE


Trackbacks 2 : Comment 0

SSH login without password

CS/Linux 2014.03.26 15:01

원문 : http://www.linuxproblem.org/art_9.html


a@A 에서 b@B 로 password 없이 로그인

a@A:~> ssh-keygen -t rsa
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'


Trackback 0 : Comment 0

Linux IO Stack Diagram

CS/Linux 2012.11.01 22:33

원문 : http://www.thomas-krenn.com/en/oss/linux-io-stack-diagram/linux-io-stack-diagram_v0.1.pdf



Trackback 0 : Comment 0

이미지 파일 생성 / 마운트

CS/Linux 2012.11.01 22:06

# dd if=/dev/zero of=disk.img bs=4k count=1024

# mkfs.ext3 -F disk.img


# mount -o loop disk.img mount_point

or

# losetup /dev/loop0 disk.img

# mount /dev/loop mount_point


Trackback 0 : Comment 0

Ubuntu에서 고정 IP 설정

CS/Linux 2011.09.08 13:38
/etc/network/interfaces

auto lo

iface lo inet loopback


auto eth0

iface ethX inet static

address X.X.X.X

netmask 255.255.255.0

gateway X.X.X.X

dns-nameservers 8.8.8.8


/etc/resolv.conf

nameserver 8.8.8.8


tags : IP, Network
Trackback 0 : Comment 0

SSH login without password

CS/Linux 2011.09.08 13:29
원문 : http://linuxproblem.org/art_9.html

a@A:~> ssh-keygen -t rsa
a@A:~> ssh b@B mkdir -p .ssh
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'


tags : ssh
Trackback 0 : Comment 0

Why not mmap?

CS/Linux 2011.05.20 10:36
원문 : http://useless-factor.blogspot.com/2011/05/why-not-mmap.html

mmap() is a beautiful interface. Rather than accessing files through a series of read and write operations, mmap() lets you virtually load the whole file into a big array and access whatever part you want just like you would with other RAM. (It lets you do other things, too—in particular, it's the basis of memory allocation. See the man page for details.) In this article, I'll be discussing mmap() on Linux, as it works in virtual memory systems like x86.

mmap() doesn't actually load the whole file in when you call it. Instead, it loads nothing in but file metadata. In the memory page table, all of the mapped pages are given the setting to make a page fault if they are read or written. The page fault handler loads the page and puts it into main memory, modifying the page table to not fault for this page later. In this way, the file is lazily read into memory. The file is written back out through the same writeback mechanism used for the page cache in buffered I/O: after some time or under some memory pressure, the contents of memory are automatically synchronized with the disk.

mmap() is a system call, implemented by the kernel. Why? As far as I can tell, what I described above could be implemented in user-space: user-space has page fault handlers and file read/write operations. But the kernel allows several other advantages:
  • If a file is being manipulated by mmap() as well as something else at the same time, the kernel can keep these in sync. 
  • The kernel can do it faster, with specialized implementations for different file systems and fewer context switches between kernel-space and user-space.
  • The kernel can do a better job, using its internal statistics to determine when to write back to disk and when to prefetch extra pages of the file. 
One situation where mmap() looks useful is databases. What could be easier for a database implementor than an array of "memory" that's transparently persisted to disk? Database authors often think they know better than the OS, so they like to have explicit control over caching policy. And various file and memory operations give you this, in conjunction with mmap():
  • mlock() lets you force a series of pages to be held in physical memory, and munlock() lets you release it. Memory locking here is basically equivalent to making part of the file present in the user-space cache, when no swap is configured on the server.

    Memory locking can be dangerous in an environment with many processes running because the out-of-memory killer (OOM killer) might some other process as a result of your profligate use of memory. However, the use of cgroups or virtualization can mitigate this possibility and provide isolation.
  • madvise() and posix_fadvise let you give the OS hints about how to behave with respect to the file. These can be used to encourage things to be pulled into memory or pushed out. MADV_DONTNEED is a quick call to zero a series of pages completely, and it could be translated into TRIM on SSDs.
  • fdatasync() lets a a process force some data onto the disk right now, rather than trusting writeback to get it there eventually. This is useful for implementing durable transactions.
Great! And in Linux, you can open up a raw block device just by opening a file like /dev/hda1 and use mmap() straight from there, so this gives database implementors a way to control the whole disk with the same interface. This is great if you're a typical database developer who doesn't like the OS and doesn't trust the file system.

So this sounds like a nice, clean way to write a database or something else that does serious file manipulation. Some databases use this, for example MongoDB. But the more advanced database implementations tend to open the database file in O_DIRECT mode and implement their own caching system in user-space. Whereas mmap() lets you use the hardware (on x86) page tables for the indirection between the logical address of the data and where it's stored in physical memory, these databases force you to go through an extra indirection in their own data structures. And these databases have to implement their own caches, even though the resulting caches often aren't smarter than the default OS cache. (The logic that makes the caching smarter is often encoded in an application-specific prefetcher, which can be done pretty clearly though memory mapping.)

A problem with mmap()

High-performance databases often get lots of requests. So many requests that, if they were to spawn a thread for each one of them, the overhead of a kernel task per request would slow them down (where task means 'thread or process', in Linux terminology). There's a bit of overhead for threads:
  • Each thread must have its own stack, which takes up memory (though this is mitigated by the lazy allocation of physical memory to back stacks, which is done by default) 
  • Some Linux CPU schedulers use a lot of CPU themselves. So blocking and then getting resumed has a certain amount of overhead. In particular, overhead is incurred so that the scheduler can be completely fair, and so that it can load-balance between cores.
To solve these issues, database implementors often respond to each request with a user-level coroutine, or even with an explicitly managed piece of state sent around through various callbacks.

Let's say we have a coroutine responding to a database request, and this coroutine wants to read from the database in a location that is currently stored on disk. If it accesses the big array, then it will cause a memory fault leading to a disk read. This will make the current task block until the disk read can be completed. But we don't want the whole task to block—we just want to switch to another coroutine when we have to wait, and we want to execute that coroutine from the same task.

The typical way around this problem is using asynchronous or non-blocking operations. For non-blocking I/O, there's epoll, which works for some kinds of files. For direct I/O on disk, Linux provides a different interface called asynchronous I/O, with system calls like io_submit. These two mechanisms can be hooked up with an eventfd, which is triggered whenever there are AIO results, using the undocumented system call io_set_eventfd. The basic idea is that you set up a bunch of requests in an object, and then you have a main loop, driven by epoll, where you repeatedly ask for the next available event. The coroutine scheduler resumes the coroutine that had the event complete on it, and executes that coroutine until it blocks again. Details about using this mechanism are a bit obtuse, but not very deep or complicated.

A proposed solution

What the mmap() interface is missing is a non-blocking way to access memory. Maybe this would take the form of a call based around mlock, like

int mlock_eventfd(const void *addr, ssize_t len, int eventfd);


which would trigger the eventfd once the memory from addr going length len was locked in memory. The eventfd could be placed in an epoll loop and then the memory requested would be dereferenced for real once it was locked. A similar mechanism would be useful for fdatasync.

We could implement mlock_eventfd in user-space using a thread pool, and the same goes for fdatasync. But this would probaly eliminate the performance advantages of using coroutines in the first place, since accessing the disk is pretty frequent in databases.

As databases and the devices that underlie them grow more complex, it becomes difficult to manage this complexity. The operating system provides a useful layer of indirection between the database and the drive, but old and messy interfaces make the use of the OS more difficult. Clean, high-level OS interfaces which let applications take full advantage of the hardware and kernel-internal mechanisms and statistics would be a great boon to further database development, allowing the explosion of new databases and solid-state drives to be fully exploited.
tags : mmap
Trackback 0 : Comment 0

[LINUX] execl

CS/Linux 2011.03.14 15:50
참고 : 
Man pages for execl, getenv


#include <unistd.h>

extern char **environ;

int execl (const char *path, const char *arg0, ... /*, (char *)0 */);
int execle(const char *path, const char *arg0, ... /*, (char *)0, char *const envp[] */);
int execlp(const char *file, const char *arg0, ... /*, (char *)0 */);

int execv (const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execve(const char *path, char *const argv[], char *const envp[]);
int execvP(const char *file, const char *search_path, char *const argv[]);

만약 exec()계열의 함수가 리턴을 한다면, 에러가 발생한 것이다. 이 때 리턴 값은 -1 이고 errno변수값이 설정된다.

execlp(), execvp() 함수는 PATH환경변수에 지정된 패스에서 file을 찾는다. 
만약 이 변수가 지정되지 않았다면, <paths.h>에 지정되어 있는 _PATH_DEFPATH 에 따라 지정된다.(일반사용자- /usr/bin:/bin)
execvP()는 탐색 경로를 인자에 지정한다.

char *const envp[] = {"SOMEKEY1=somevalue1", "SOMEKEY2=somevalue2", NULL};
char * const argv[] = {"/usr/bin/uname", "-a", NULL};

execl ("/usr/bin/uname",      "/usr/bin/uname",      "-a", NULL);
execle("/path/to/executable", "/path/to/executable",       NULL, envp);
execlp("uname",               "uname",               "-a", NULL);

execv ("/usr/bin/uname",    argv);
execvp("uname",             argv);
execve("/usr/bin/uname",    argv, envp);
evecvP("uname", "/usr/bin", argv);








Trackback 0 : Comment 0

티스토리 툴바